X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=fd.c;h=9b6c6917232eb5063bb3acaad51a24ea53226389;hb=d9566a07057f68b0effd404e2da7817555f35383;hp=2e05313ea26ece1fd65315e80561fdd626f45fe1;hpb=9de1287d67c9562e9140c6dc7deb0c01c4e10cc0;p=paraslash.git diff --git a/fd.c b/fd.c index 2e05313e..9b6c6917 100644 --- a/fd.c +++ b/fd.c @@ -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)