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