mirror of
https://github.com/corda/corda.git
synced 2025-02-02 17:21:06 +00:00
use MapViewOfFile instead of mmap on Windows
This commit is contained in:
parent
a0d763d871
commit
728a6ba706
@ -14,7 +14,11 @@
|
|||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
#include "sys/stat.h"
|
#include "sys/stat.h"
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
#include "sys/mman.h"
|
#include "sys/mman.h"
|
||||||
|
#endif
|
||||||
#include "fcntl.h"
|
#include "fcntl.h"
|
||||||
#include "unistd.h"
|
#include "unistd.h"
|
||||||
|
|
||||||
@ -152,8 +156,29 @@ main(int argc, const char** argv)
|
|||||||
struct stat s;
|
struct stat s;
|
||||||
int r = fstat(fd, &s);
|
int r = fstat(fd, &s);
|
||||||
if (r != -1) {
|
if (r != -1) {
|
||||||
|
#ifdef WIN32
|
||||||
|
HANDLE fm;
|
||||||
|
HANDLE h = (HANDLE) _get_osfhandle (fd);
|
||||||
|
|
||||||
|
fm = CreateFileMapping(
|
||||||
|
h,
|
||||||
|
NULL,
|
||||||
|
PAGE_READONLY,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
NULL);
|
||||||
|
data = static_cast<uint8_t*>(MapViewOfFile(
|
||||||
|
fm,
|
||||||
|
FILE_MAP_READ,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
s.st_size));
|
||||||
|
|
||||||
|
CloseHandle(fm);
|
||||||
|
#else
|
||||||
data = static_cast<uint8_t*>
|
data = static_cast<uint8_t*>
|
||||||
(mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0));
|
(mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0));
|
||||||
|
#endif
|
||||||
size = s.st_size;
|
size = s.st_size;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -173,7 +198,11 @@ main(int argc, const char** argv)
|
|||||||
fprintf(stderr, "unable to open %s\n", argv[2]);
|
fprintf(stderr, "unable to open %s\n", argv[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
UnmapViewOfFile(data);
|
||||||
|
#else
|
||||||
munmap(data, size);
|
munmap(data, size);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
perror(argv[0]);
|
perror(argv[0]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user