mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core: FileMapping fixed in Linux
This commit is contained in:
parent
65da0c4e72
commit
8c12e9f0dc
3 changed files with 20 additions and 7 deletions
|
|
@ -7,13 +7,17 @@ CONSOLE_APP_MAIN
|
|||
StdLogSetup(LOG_COUT|LOG_FILE);
|
||||
|
||||
String test;
|
||||
for(int i = 0; i < 100; i++)
|
||||
for(int i = 0; i < 10000; i++)
|
||||
test << i << " " << i * 12345678 << "\n";
|
||||
|
||||
int sz = test.GetCount();
|
||||
|
||||
DUMP(sz);
|
||||
|
||||
String path = GetHomeDirFile("mapped");
|
||||
|
||||
// SaveFile(path, String('0', sz));
|
||||
|
||||
{
|
||||
FileMapping m;
|
||||
m.Create(path, sz);
|
||||
|
|
@ -27,6 +31,12 @@ CONSOLE_APP_MAIN
|
|||
ASSERT(memcmp(m.Map(), ~test, sz) == 0);
|
||||
}
|
||||
|
||||
{
|
||||
FileMapping m(path);
|
||||
for(int i = 0; i < sz; i++)
|
||||
ASSERT(*m.Map(i, 1) == test[i]);
|
||||
}
|
||||
|
||||
DeleteFile(path);
|
||||
|
||||
LOG("============ OK");
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ FileMapping::FileMapping(const char *file_)
|
|||
#ifdef PLATFORM_WIN32
|
||||
bool FileMapping::Open(const char *filename, dword mode, int64 wsize)
|
||||
#else
|
||||
bool FileMapping::Open(const char *filename, dword mode, mode_t acm)
|
||||
bool FileMapping::Open(const char *filename, dword mode, int64 wsize, mode_t acm)
|
||||
#endif
|
||||
{
|
||||
Close();
|
||||
|
|
@ -65,6 +65,10 @@ bool FileMapping::Open(const char *filename, dword mode, mode_t acm)
|
|||
#else
|
||||
if(!FileStream::OpenHandle(filename, mode, hfile, filesize, acm))
|
||||
return false;
|
||||
if(write) {
|
||||
ftruncate(hfile, wsize);
|
||||
filesize = wsize;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
|
@ -86,9 +90,10 @@ byte *FileMapping::Map(int64 mapoffset, size_t maplen)
|
|||
size_t rawsz = (size_t)min<int64>((maplen + (size_t)(mapoffset - rawoff) + gran - 1) & -gran, filesize - rawoff);
|
||||
rawoffset = rawoff;
|
||||
rawsize = rawsz;
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
rawbase = (byte *)MapViewOfFile(hmap, write ? FILE_MAP_WRITE : FILE_MAP_READ,
|
||||
(dword)(rawoffset >> 32), (dword)(rawoffset >> 0), rawsize);
|
||||
HIDWORD(rawoffset), LODWORD(rawoffset), rawsize);
|
||||
#else
|
||||
rawbase = (byte *)mmap(0, rawsize,
|
||||
PROT_READ | (write ? PROT_WRITE : 0),
|
||||
|
|
@ -100,7 +105,7 @@ byte *FileMapping::Map(int64 mapoffset, size_t maplen)
|
|||
hfile, rawoffset);
|
||||
#endif
|
||||
#ifdef PLATFORM_POSIX
|
||||
if(rawbase == (byte *)~0)
|
||||
if(rawbase == (byte *)-1)
|
||||
#else
|
||||
if(!rawbase)
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@ public:
|
|||
|
||||
#ifdef PLATFORM_WIN32
|
||||
bool Open(const char *filename, dword mode = FileStream::READ, int64 filesize = 0);
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_POSIX
|
||||
#else
|
||||
bool Open(const char *filename, dword mode = FileStream::READ, int64 filesize = 0, mode_t acm = 0644);
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue