From 728a6ba7062835aec136da63cd996ee0d9117e84 Mon Sep 17 00:00:00 2001 From: Stan Date: Tue, 24 Nov 2009 08:24:37 -0700 Subject: [PATCH] use MapViewOfFile instead of mmap on Windows --- src/binaryToObject/main.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/binaryToObject/main.cpp b/src/binaryToObject/main.cpp index 0200dd4123..0e69698847 100644 --- a/src/binaryToObject/main.cpp +++ b/src/binaryToObject/main.cpp @@ -14,7 +14,11 @@ #include "string.h" #include "sys/stat.h" +#ifdef WIN32 +#include +#else #include "sys/mman.h" +#endif #include "fcntl.h" #include "unistd.h" @@ -152,8 +156,29 @@ main(int argc, const char** argv) struct stat s; int r = fstat(fd, &s); 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(MapViewOfFile( + fm, + FILE_MAP_READ, + 0, + 0, + s.st_size)); + + CloseHandle(fm); +#else data = static_cast (mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0)); +#endif size = s.st_size; } close(fd); @@ -173,7 +198,11 @@ main(int argc, const char** argv) fprintf(stderr, "unable to open %s\n", argv[2]); } +#ifdef WIN32 + UnmapViewOfFile(data); +#else munmap(data, size); +#endif } else { perror(argv[0]); }