From 26777ace7c714253359a8c57b1c9ca22317a9c30 Mon Sep 17 00:00:00 2001 From: Guido Draheim Date: Thu, 1 Mar 2018 19:57:36 +0100 Subject: [PATCH] __mmap.h does not need to store the fileMapping handle according to MINGW patches #30 --- zzip/__mmap.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/zzip/__mmap.h b/zzip/__mmap.h index 07af31d..80c976d 100644 --- a/zzip/__mmap.h +++ b/zzip/__mmap.h @@ -44,8 +44,7 @@ #ifndef MAP_FAILED #define MAP_FAILED 0 #endif -/* we (ab)use the "*user" variable to store the FileMapping handle */ - /* which assumes (sizeof(long) == sizeof(HANDLE)) */ +/* we had used the plugin->sys variable for (user) but not anymore */ static size_t win32_getpagesize (void) { @@ -58,14 +57,14 @@ static void* win32_mmap (long* user, int fd, zzip_off_t offs, size_t len) return 0; { HANDLE hFile = (HANDLE)_get_osfhandle(fd); + HANDLE fileMapping = NULL; if (hFile) - *user = (int) CreateFileMapping (hFile, 0, PAGE_READONLY, 0, 0, NULL); - if (*user) + fileMapping = CreateFileMapping (hFile, 0, PAGE_READONLY, 0, 0, NULL); + if (fileMapping != NULL) { - char* p = 0; - p = MapViewOfFile(*(HANDLE*)user, FILE_MAP_READ, 0, offs, len); - if (p) return p + offs; - CloseHandle (*(HANDLE*)user); *user = 1; + char* p = MapViewOfFile(fileMapping, FILE_MAP_READ, 0, offs, len); + CloseHandle (fileMapping); *user = 1; + if (p) return p; } return MAP_FAILED; } @@ -73,7 +72,6 @@ static void* win32_mmap (long* user, int fd, zzip_off_t offs, size_t len) static void win32_munmap (long* user, char* fd_map, size_t len) { UnmapViewOfFile (fd_map); - CloseHandle (*(HANDLE*)user); *user = 1; } #define _zzip_mmap(user, fd, offs, len) \ -- 2.40.0