OSDN Git Service

[Support/UNIX] posix_fallocate() can fail with EINVAL.
authorDavide Italiano <davide@freebsd.org>
Tue, 7 Nov 2017 00:47:04 +0000 (00:47 +0000)
committerDavide Italiano <davide@freebsd.org>
Tue, 7 Nov 2017 00:47:04 +0000 (00:47 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317535 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Unix/Path.inc

index 781a911..2ecb973 100644 (file)
@@ -426,7 +426,7 @@ std::error_code resize_file(int FD, uint64_t Size) {
   // 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