diff --git a/CHANGES b/CHANGES index d0f0b54..ccdce4d 100644 --- a/CHANGES +++ b/CHANGES @@ -24,6 +24,8 @@ add io_fd_flags so the caller can tell io_fd whether the socket is blocking (saves one fcntl syscall) more constness for stralloc and buffer + mmap_read/mmap_shared on zero length files no longer fail but return a + zero length buffer 0.29: save 8 bytes in taia.h for 64-bit systems diff --git a/mmap/mmap_read.c b/mmap/mmap_read.c index 14dd6d9..7d9055f 100644 --- a/mmap/mmap_read.c +++ b/mmap/mmap_read.c @@ -30,9 +30,12 @@ extern const char* mmap_read(const char* filename,size_t * filesize) { register off_t o=lseek(fd,0,SEEK_END); if (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1) { close(fd); return 0; } *filesize=(size_t)o; - map=mmap(0,*filesize,PROT_READ,MAP_SHARED,fd,0); - if (map==(char*)-1) - map=0; + if (o>0) { + map=mmap(0,*filesize,PROT_READ,MAP_SHARED,fd,0); + if (map==(char*)-1) + map=0; + } else + map=""; close(fd); return map; } diff --git a/mmap/mmap_shared.c b/mmap/mmap_shared.c index d4c99ff..3064d7c 100644 --- a/mmap/mmap_shared.c +++ b/mmap/mmap_shared.c @@ -30,9 +30,12 @@ extern char* mmap_shared(const char* filename,size_t * filesize) { register off_t o=lseek(fd,0,SEEK_END); if (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1) { close(fd); return 0; } *filesize=(size_t)o; - map=mmap(0,*filesize,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); - if (map==(char*)-1) - map=0; + if (o) { + map=mmap(0,*filesize,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); + if (map==(char*)-1) + map=0; + } else + map=""; close(fd); return map; } diff --git a/mmap/mmap_unmap.c b/mmap/mmap_unmap.c index 994e486..ce8e419 100644 --- a/mmap/mmap_unmap.c +++ b/mmap/mmap_unmap.c @@ -13,6 +13,6 @@ int mmap_unmap(const char* mapped,size_t maplen) { (void)maplen; return UnmapViewOfFile(mapped)?0:-1; #else - return munmap((char*)mapped,maplen); + return maplen ? munmap((char*)mapped,maplen) : 0; #endif }