]> mj.ucw.cz Git - libucw.git/commitdiff
Mapping of zero-length files returns just a random non-zero address.
authorMartin Mares <mj@ucw.cz>
Tue, 27 Mar 2001 17:41:01 +0000 (17:41 +0000)
committerMartin Mares <mj@ucw.cz>
Tue, 27 Mar 2001 17:41:01 +0000 (17:41 +0000)
With this fix, empty indices are generated correctly.

lib/mmap.c

index e461e1ee2838d48f0aded5e1b59765cf1a567a22..87a2047f7038df21268eb32ce0ce958ec6ab8223 100644 (file)
@@ -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;