]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - fd.c
gui: Rename client_cmd_cmdline() to para_cmd().
[paraslash.git] / fd.c
diff --git a/fd.c b/fd.c
index a04232f84b3fd239249c866cb5a109551ad2b926..3a8406d9c9fd1454a0807c8584bae78aa1b2f543 100644 (file)
--- 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)