X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=fd.c;h=3a8406d9c9fd1454a0807c8584bae78aa1b2f543;hp=a04232f84b3fd239249c866cb5a109551ad2b926;hb=4744d937c4160898d1fe151257606430750e580c;hpb=f0e41e36c3f1a3a5bb6ff66d92d2814391d8f908 diff --git a/fd.c b/fd.c index a04232f8..3a8406d9 100644 --- a/fd.c +++ b/fd.c @@ -617,6 +617,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)