diff --git a/mmap/mmap_private.c b/mmap/mmap_private.c index 1850ce0..771ecf9 100644 --- a/mmap/mmap_private.c +++ b/mmap/mmap_private.c @@ -28,7 +28,7 @@ char* mmap_private(const char* filename,size_t * filesize) { char *map; if (fd>=0) { 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; } + if (o==0 || (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1)) { close(fd); return 0; } *filesize=(size_t)o; map=(char*)mmap(0,*filesize,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0); if (map==(char*)-1) diff --git a/mmap/mmap_read.c b/mmap/mmap_read.c index 7d9055f..1dfc597 100644 --- a/mmap/mmap_read.c +++ b/mmap/mmap_read.c @@ -28,7 +28,7 @@ extern const char* mmap_read(const char* filename,size_t * filesize) { char *map; if (fd>=0) { 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; } + if (o==0 || (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1)) { close(fd); return 0; } *filesize=(size_t)o; if (o>0) { map=mmap(0,*filesize,PROT_READ,MAP_SHARED,fd,0); diff --git a/mmap/mmap_readat.c b/mmap/mmap_readat.c index e7de33d..0503d6b 100644 --- a/mmap/mmap_readat.c +++ b/mmap/mmap_readat.c @@ -20,7 +20,7 @@ extern const char* mmap_readat(const char* filename,size_t * filesize,int dirfd) char *map; if (fd>=0) { 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; } + if (o==0 || (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1)) { close(fd); return 0; } *filesize=(size_t)o; if (o>0) { map=mmap(0,*filesize,PROT_READ,MAP_SHARED,fd,0); diff --git a/mmap/mmap_shared.c b/mmap/mmap_shared.c index 3064d7c..60f1cb1 100644 --- a/mmap/mmap_shared.c +++ b/mmap/mmap_shared.c @@ -28,7 +28,7 @@ extern char* mmap_shared(const char* filename,size_t * filesize) { char *map; if (fd>=0) { 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; } + if (o==0 || (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1)) { close(fd); return 0; } *filesize=(size_t)o; if (o) { map=mmap(0,*filesize,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);