From b19bb73905fd05a9388dbce5c44506412c4428ed Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 24 May 2002 21:15:01 +0000 Subject: [PATCH] mmap_file() calls die() instead of returning failure. --- lib/mmap.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/mmap.c b/lib/mmap.c index 2b057b6c..43668bbc 100644 --- a/lib/mmap.c +++ b/lib/mmap.c @@ -1,7 +1,7 @@ /* * Sherlock Library -- Mapping of Files * - * (c) 1999 Martin Mares + * (c) 1999--2002 Martin Mares */ #include "lib/lib.h" @@ -20,22 +20,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; - 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 ""; + x = mmap(NULL, st.st_size, writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, fd, 0); + if (x == MAP_FAILED) + die("mmap(%s): %m", name); } + else /* For empty file, we can return any non-zero address */ + x = ""; close(fd); return x; } -- 2.39.2