aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Unix/Path.inc
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-07-19 20:19:56 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-07-19 20:19:56 +0000
commit3816c53f040cc6aa06425978dd504b0bd5b7899c (patch)
tree1de5a1b9eb85436d409e2c3aac6d2d3f45a5641e /llvm/lib/Support/Unix/Path.inc
parent2f984cab4fa7b8cf07e87965fb334e9d16e7e296 (diff)
downloadllvm-3816c53f040cc6aa06425978dd504b0bd5b7899c.zip
llvm-3816c53f040cc6aa06425978dd504b0bd5b7899c.tar.gz
llvm-3816c53f040cc6aa06425978dd504b0bd5b7899c.tar.bz2
Use posix_fallocate instead of ftruncate.
This makes sure that space is actually available. With this change running lld on a full file system causes it to exit with failed to open foo: No space left on device instead of crashing with a sigbus. llvm-svn: 276017
Diffstat (limited to 'llvm/lib/Support/Unix/Path.inc')
-rw-r--r--llvm/lib/Support/Unix/Path.inc9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 84aafcb..ea439c6 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -329,8 +329,17 @@ std::error_code rename(const Twine &from, const Twine &to) {
}
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
+ // 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();
}