[llvm] r317535 - [Support/UNIX] posix_fallocate() can fail with EINVAL.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 6 16:47:04 PST 2017


Author: davide
Date: Mon Nov  6 16:47:04 2017
New Revision: 317535

URL: http://llvm.org/viewvc/llvm-project?rev=317535&view=rev
Log:
[Support/UNIX] posix_fallocate() can fail with EINVAL.

According to the docs on opegroup.org, the function can return
EINVAL if:

The len argument is less than zero, or the offset argument is less
than zero, or the underlying file system does not support this
operation.

I'd say it's a peculiar choice (when EONOTSUPP is right there), but
let's keep POSIX happy for now. This was independently discovered
by Mark Millard (on FreeBSD/ZFS).

Quickly ack'ed by Rui on IRC.

Modified:
    llvm/trunk/lib/Support/Unix/Path.inc

Modified: llvm/trunk/lib/Support/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=317535&r1=317534&r2=317535&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc (original)
+++ llvm/trunk/lib/Support/Unix/Path.inc Mon Nov  6 16:47:04 2017
@@ -426,7 +426,7 @@ std::error_code resize_file(int FD, uint
   // If we have posix_fallocate use it. Unlike ftruncate it always allocates
   // space, so we get an error if the disk is full.
   if (int Err = ::posix_fallocate(FD, 0, Size)) {
-    if (Err != EOPNOTSUPP)
+    if (Err != EINVAL && Err != EOPNOTSUPP)
       return std::error_code(Err, std::generic_category());
   }
 #endif




More information about the llvm-commits mailing list