]> granicus.if.org Git - zziplib/commitdiff
__mmap.h does not need to store the fileMapping handle according to MINGW patches #30
authorGuido Draheim <guidod@gmx.de>
Thu, 1 Mar 2018 18:57:36 +0000 (19:57 +0100)
committerGuido Draheim <guidod@gmx.de>
Thu, 1 Mar 2018 18:57:36 +0000 (19:57 +0100)
zzip/__mmap.h

index 07af31d49663486abbee0df8fe441a9159f7cf38..80c976d242ca6dd3d98c3d0749b01c5d43f968e3 100644 (file)
@@ -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) \