提交linux编辑slfio
This commit is contained in:
parent
abd149a6e4
commit
5901527c6e
|
|
@ -48,7 +48,7 @@ typedef void *HANDLE;
|
|||
#else
|
||||
typedef unsigned int DWORD;
|
||||
typedef DWORD *LPDWORD;
|
||||
typedef void *HANDLE;
|
||||
typedef unsigned int HANDLE;
|
||||
typedef unsigned char byte;
|
||||
typedef bool BOOL;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#endif // WIN32
|
||||
#include "slf.h"
|
||||
#include <QDir>
|
||||
|
|
@ -59,11 +62,11 @@ wchar_t* AnsiToUnicode(const char* szStr)
|
|||
}
|
||||
int IsMappingMem(const char *MemName)
|
||||
{
|
||||
QString slf1=MemName;
|
||||
slf1.replace("\\","/");
|
||||
slf1.replace(".","_");
|
||||
#ifdef WIN32
|
||||
QString slf1=MemName;
|
||||
slf1.replace("\\","/");
|
||||
slf1.replace(".","_");
|
||||
wchar_t *pname=AnsiToUnicode(slf1.toStdString().c_str());
|
||||
wchar_t *pname=AnsiToUnicode(slf1.toStdString().c_str());
|
||||
HANDLE hMapFile = OpenFileMapping(FILE_MAP_READ,
|
||||
false,
|
||||
pname);
|
||||
|
|
@ -72,15 +75,19 @@ int IsMappingMem(const char *MemName)
|
|||
CloseHandle(hMapFile);
|
||||
return fInit;
|
||||
#else
|
||||
return 0;
|
||||
int hMapFile = open(slf1.toStdString().c_str(), O_RDONLY);
|
||||
if (hMapFile<0)
|
||||
return 0;
|
||||
close(hMapFile);
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
bool MappingMem(HANDLE *hHandle,LPSTR *hMem,int len,const char* name)
|
||||
{
|
||||
QString slf1=name;
|
||||
slf1.replace("\\","/");
|
||||
slf1.replace(".","_");
|
||||
#ifdef WIN32
|
||||
QString slf1=name;
|
||||
slf1.replace("\\","/");
|
||||
slf1.replace(".","_");
|
||||
wchar_t *pname=AnsiToUnicode(slf1.toStdString().c_str());
|
||||
HANDLE hMapFile = OpenFileMapping(FILE_MAP_READ|FILE_MAP_WRITE,
|
||||
false,
|
||||
|
|
@ -105,11 +112,16 @@ bool MappingMem(HANDLE *hHandle,LPSTR *hMem,int len,const char* name)
|
|||
0, // high offset: map from
|
||||
0, // low offset: beginning
|
||||
0); // default: map entire file
|
||||
if (*hMem == NULL) return FALSE;
|
||||
return TRUE;
|
||||
#else
|
||||
return FALSE;
|
||||
HANDLE hMapFile = open(slf1.toStdString().c_str(),O_RDONLY));
|
||||
if((hMapFile < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
*hMem = (LPSTR)mmap(0,0,PROT_READ,MAP_SHARED,hMapFile,0));
|
||||
#endif
|
||||
if (*hMem == NULL) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CloseView(HANDLE hMapObject,LPVOID lpvMem)
|
||||
|
|
@ -118,6 +130,8 @@ void CloseView(HANDLE hMapObject,LPVOID lpvMem)
|
|||
if(lpvMem)UnmapViewOfFile(lpvMem);
|
||||
if(hMapObject)CloseHandle(hMapObject);
|
||||
#else
|
||||
if(lpvMem)munmap(m_rbuf, m_mapsize);
|
||||
if(hMapObject)close(hMapObject);
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user