X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fmmap.c;h=aa63622259d50034fce4b774dc600c92dcf1828b;hb=86919305a08aa88b3a60c3216752291ba7f0b496;hp=e461e1ee2838d48f0aded5e1b59765cf1a567a22;hpb=4bb1ae1d27874e3c1bf2817b740da096ac322f15;p=libucw.git diff --git a/lib/mmap.c b/lib/mmap.c index e461e1ee..aa636222 100644 --- a/lib/mmap.c +++ b/lib/mmap.c @@ -1,7 +1,10 @@ /* - * Sherlock Library -- Mapping of Files + * UCW Library -- Mapping of Files * - * (c) 1999 Martin Mares + * (c) 1999--2002 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. */ #include "lib/lib.h" @@ -12,11 +15,6 @@ #include #include -#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) { @@ -25,17 +23,19 @@ mmap_file(byte *name, unsigned *len, int writeable) void *x; if (fd < 0) - return NULL; + die("open(%s): %m", name); if (fstat(fd, &st) < 0) - x = NULL; - else + die("fstat(%s): %m", name); + if (len) + *len = st.st_size; + if (st.st_size) { - 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; + die("mmap(%s): %m", name); } + else /* For empty file, we can return any non-zero address */ + x = ""; close(fd); return x; }