OSDN Git Service

If posix_fallocate returns EOPNOTSUPP, fallback to ftruncate.
authorJoerg Sonnenberger <joerg@bec.de>
Fri, 5 May 2017 17:55:58 +0000 (17:55 +0000)
committerJoerg Sonnenberger <joerg@bec.de>
Fri, 5 May 2017 17:55:58 +0000 (17:55 +0000)
This can happen at least on NetBSD.

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

lib/Support/Unix/Path.inc

index 93f8982..fa28ba1 100644 (file)
@@ -421,14 +421,15 @@ std::error_code resize_file(int FD, uint64_t Size) {
 #if defined(HAVE_POSIX_FALLOCATE)
   // 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))
-    return std::error_code(Err, std::generic_category());
-#else
+  if (int Err = ::posix_fallocate(FD, 0, Size)) {
+    if (Err != EOPNOTSUPP)
+      return std::error_code(Err, std::generic_category());
+  }
+#endif
   // Use ftruncate as a fallback. It may or may not allocate space. At least on
   // OS X with HFS+ it does.
   if (::ftruncate(FD, Size) == -1)
     return std::error_code(errno, std::generic_category());
-#endif
 
   return std::error_code();
 }