diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2019-03-18 19:45:34 +0100 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2019-03-18 19:45:34 +0100 |
| commit | ec6f8c4fe162500645109eb24856051c97bfb2fe (patch) | |
| tree | 95cc40de4f88c3d1e1ee4dcac1b093df984126ec /src | |
| parent | 984c5b553954ebed29d01b29083323e03f78ac9d (diff) | |
| download | cc4group-ec6f8c4fe162500645109eb24856051c97bfb2fe.tar.gz cc4group-ec6f8c4fe162500645109eb24856051c97bfb2fe.zip | |
Remove the extra argument from cc4group_mmap and cc4group_munmap as its actually not needed
Diffstat (limited to 'src')
| -rw-r--r-- | src/cc4group.c | 19 | ||||
| -rw-r--r-- | src/platform/platform.h | 4 | ||||
| -rw-r--r-- | src/platform/unix.c | 6 | ||||
| -rw-r--r-- | src/platform/windows.c | 11 |
4 files changed, 15 insertions, 25 deletions
diff --git a/src/cc4group.c b/src/cc4group.c index 3947acf..56f4175 100644 --- a/src/cc4group.c +++ b/src/cc4group.c @@ -274,7 +274,7 @@ static void deleteChildren(GroupEntryList* const entries) GroupEntryListDestroy(entries); } -static void* cc4group_mapSizedWriteFd(CC4Group* const this, int fd, size_t size, void** extra) +static void* cc4group_mapSizedWriteFd(CC4Group* const this, int fd, size_t size) { // allocate file size // https://gist.github.com/marcetcheverry/991042 @@ -290,18 +290,17 @@ static void* cc4group_mapSizedWriteFd(CC4Group* const this, int fd, size_t size, return MAP_FAILED; } - return cc4group_mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0, extra); + return cc4group_mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); } typedef struct { void* addr; size_t size; - void* extra; } MunmapData; static void cc4group_unmapTmpMemoryFile(MunmapData* data) { - if(cc4group_munmap(data->addr, data->size, data->extra) == -1) + if(cc4group_munmap(data->addr, data->size) == -1) { fprintf(stderr, "WARNING: munmap: Unmapping tempory file failed: %s\n", strerror(errno)); } @@ -320,8 +319,7 @@ static void* cc4group_createTmpMemoryFile(CC4Group* const this, const size_t siz return NULL; } - void* mmapExtra; - ret = cc4group_mapSizedWriteFd(this, tmpFile, size, &mmapExtra); + ret = cc4group_mapSizedWriteFd(this, tmpFile, size); if(ret == MAP_FAILED) { // error message is set in the method @@ -335,7 +333,7 @@ static void* cc4group_createTmpMemoryFile(CC4Group* const this, const size_t siz { SET_ERRNO_ERROR("malloc: allocating memory for cleanup data"); - if(cc4group_munmap(ret, size, mmapExtra) == -1) + if(cc4group_munmap(ret, size) == -1) { SET_ERRNO_ERROR("malloc: allocating memory for cleanup data; additionally munmap: unmapping the mapped file failed"); } @@ -343,7 +341,7 @@ static void* cc4group_createTmpMemoryFile(CC4Group* const this, const size_t siz } else { - *unmapData = (MunmapData){ret, size, mmapExtra}; + *unmapData = (MunmapData){ret, size}; *cleanupJob = (CC4Group_CleanupJob){(CC4Group_CleanupFunc)cc4group_unmapTmpMemoryFile, unmapData}; } } @@ -835,7 +833,6 @@ static bool cc4group_setSubRoot(CC4Group* const this, const char* const subPath) static bool cc4group_uncompressGroupFromFile(CC4Group* const this, const char* const path) { uint8_t* mappedFile = MAP_FAILED; - void* mapExtra; bool success = false; char* slash = NULL; @@ -894,7 +891,7 @@ static bool cc4group_uncompressGroupFromFile(CC4Group* const this, const char* c } off_t size = st.st_size; - mappedFile = cc4group_mmap(NULL, size, PROT_READ, MAP_PRIVATE, file, 0, &mapExtra); + mappedFile = cc4group_mmap(NULL, size, PROT_READ, MAP_PRIVATE, file, 0); if(close(file) == -1) { @@ -914,7 +911,7 @@ static bool cc4group_uncompressGroupFromFile(CC4Group* const this, const char* c ret: if(mappedFile != MAP_FAILED) { - if(cc4group_munmap(mappedFile, size, mapExtra) == -1) + if(cc4group_munmap(mappedFile, size) == -1) { fprintf(stderr, "WARNING: munmap: Unmapping the group file failed: %s\n", strerror(errno)); } diff --git a/src/platform/platform.h b/src/platform/platform.h index 8e52d51..688d851 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -31,5 +31,5 @@ #define SET_BINARY(fd) #endif -void *cc4group_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset, void** extra); -int cc4group_munmap(void *addr, size_t length, void* extra);
\ No newline at end of file +void *cc4group_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); +int cc4group_munmap(void *addr, size_t length);
\ No newline at end of file diff --git a/src/platform/unix.c b/src/platform/unix.c index ecf5166..9bd8f57 100644 --- a/src/platform/unix.c +++ b/src/platform/unix.c @@ -1,13 +1,11 @@ #include "platform.h" -void *cc4group_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset, void** extra) +void *cc4group_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) { - (void)extra; return mmap(start, length, prot, flags, fd, offset); } -int cc4group_munmap(void *addr, size_t length, void* extra) +int cc4group_munmap(void *addr, size_t length) { - (void)extra; return munmap(addr, length); } diff --git a/src/platform/windows.c b/src/platform/windows.c index bd1016c..53d5038 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -17,8 +17,6 @@ #include <windows.h> #include <sys/types.h> -#include <stdio.h> - #include "platform.h" #ifdef __USE_FILE_OFFSET64 @@ -29,7 +27,7 @@ # define DWORD_LO(x) (x) #endif -void *cc4group_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset, void** extra) +void *cc4group_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) { (void)start; if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) @@ -83,22 +81,19 @@ void *cc4group_mmap(void *start, size_t length, int prot, int flags, int fd, off dwDesiredAccess |= FILE_MAP_EXECUTE; void *ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length); + CloseHandle(h); if (ret == NULL) { - CloseHandle(h); ret = MAP_FAILED; } - *extra = h; return ret; } -int cc4group_munmap(void *addr, size_t length, void* extra) +int cc4group_munmap(void *addr, size_t length) { (void)length; UnmapViewOfFile(addr); - CloseHandle(extra); - /* ruh-ro, we leaked handle from CreateFileMapping() ... */ return 0; } |
