]> mj.ucw.cz Git - libucw.git/blobdiff - lib/mmap.c
Initial version of SQL gathering utility gsql added.
[libucw.git] / 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;