Index: llvm/lib/Support/Unix/Path.inc =================================================================== --- llvm/lib/Support/Unix/Path.inc +++ llvm/lib/Support/Unix/Path.inc @@ -422,19 +422,16 @@ } 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)) { - 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. + // Resize the file using ftruncate. ftruncate may not allocate actual disk + // blocks, so even if ftruncate succeeds, subsequent writes may fail due to + // "disk full" errors. + // + // posix_fallocate guarantees that it allocates all disk blocks, but the + // function is slow unless your filesystem supports the fallocate system + // call. When it falls back, it writes null bytes on each block. So we don't + // want to use the function. if (::ftruncate(FD, Size) == -1) return std::error_code(errno, std::generic_category()); - return std::error_code(); }