]> mj.ucw.cz Git - libucw.git/blobdiff - lib/mmap.c
Forgot to commit this one during the "search by age" changes.
[libucw.git] / lib / mmap.c
index e461e1ee2838d48f0aded5e1b59765cf1a567a22..2b057b6cf7da2071508b0393a4c06d19f4f136b7 100644 (file)
 #include <sys/stat.h>
 #include <sys/mman.h>
 
-#ifndef MAP_FAILED
-#warning System includes do not define MAP_FAILED.
-#define MAP_FAILED ((void *)-1L)
-#endif
-
 void *
 mmap_file(byte *name, unsigned *len, int writeable)
 {
@@ -32,9 +27,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;