From: Martin Mares Date: Tue, 27 Mar 2001 17:41:01 +0000 (+0000) Subject: Mapping of zero-length files returns just a random non-zero address. X-Git-Tag: holmes-import~1497 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=271f4aa1f1334277cd5e052003fc795d4e3ebbc8;p=libucw.git Mapping of zero-length files returns just a random non-zero address. With this fix, empty indices are generated correctly. --- diff --git a/lib/mmap.c b/lib/mmap.c index e461e1ee..87a2047f 100644 --- a/lib/mmap.c +++ b/lib/mmap.c @@ -32,9 +32,14 @@ mmap_file(byte *name, unsigned *len, int writeable) { if (len) *len = st.st_size; - x = mmap(NULL, st.st_size, writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, fd, 0); - if (x == MAP_FAILED) - x = NULL; + if (st.st_size) + { + x = mmap(NULL, st.st_size, writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, fd, 0); + if (x == MAP_FAILED) + x = NULL; + } + else /* For empty file, we can return any non-zero address */ + return ""; } close(fd); return x;