mmap_read/mmap_shared on zero length files no longer fail but return a
zero length buffer
This commit is contained in:
parent
ed93e203a1
commit
a255cebc57
2
CHANGES
2
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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user