X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=fd.c;h=9b6c6917232eb5063bb3acaad51a24ea53226389;hp=6f9266f47a56cd8dee3e99b8651d12a89bb4069b;hb=d9566a07057f68b0effd404e2da7817555f35383;hpb=dd98d31d017bbbe16bf6711e0343b267dd6cfe89 diff --git a/fd.c b/fd.c index 6f9266f4..9b6c6917 100644 --- a/fd.c +++ b/fd.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2011 Andre Noll + * Copyright (C) 2006-2012 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -541,6 +541,22 @@ int mmap_full_file(const char *path, int open_mode, void **map, goto out; } *size = file_status.st_size; + /* + * If the file is empty, *size is zero and mmap() would return EINVAL + * (Invalid argument). This error is common enough to spend an extra + * error code which explicitly states the problem. + */ + ret = -E_EMPTY; + if (*size == 0) + goto out; + /* + * If fd refers to a directory, mmap() returns ENODEV (No such device), + * at least on Linux. "Is a directory" seems to be more to the point. + */ + ret = -ERRNO_TO_PARA_ERROR(EISDIR); + if (S_ISDIR(file_status.st_mode)) + goto out; + ret = para_mmap(*size, mmap_prot, mmap_flags, fd, 0, map); out: if (ret < 0 || !fd_ptr) @@ -563,6 +579,9 @@ out: int para_munmap(void *start, size_t length) { int err; + + if (!start) + return 0; if (munmap(start, length) >= 0) return 1; err = errno;