instead of calling mmap with a size of 0 (which will fail), skip the

syscall and fail directly
master
leitner 8 years ago
parent c3c05dd884
commit 18615acf60

@ -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)

@ -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);

@ -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);

@ -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);

Loading…
Cancel
Save