aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support/FileOutputBuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Support/FileOutputBuffer.cpp')
-rw-r--r--lib/Support/FileOutputBuffer.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp
index c62655d..b176a8b 100644
--- a/lib/Support/FileOutputBuffer.cpp
+++ b/lib/Support/FileOutputBuffer.cpp
@@ -12,12 +12,18 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Errc.h"
-#include "llvm/Support/FileOutputBuffer.h"
-#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include <system_error>
+#if !defined(_MSC_VER) && !defined(__MINGW32__)
+#include <unistd.h>
+#else
+#include <io.h>
+#endif
+
using llvm::sys::fs::mapped_file_region;
namespace llvm {
@@ -71,10 +77,17 @@ FileOutputBuffer::create(StringRef FilePath, size_t Size,
if (EC)
return EC;
+ EC = sys::fs::resize_file(FD, Size);
+ if (EC)
+ return EC;
+
auto MappedFile = llvm::make_unique<mapped_file_region>(
- FD, true, mapped_file_region::readwrite, Size, 0, EC);
+ FD, mapped_file_region::readwrite, Size, 0, EC);
+ int Ret = close(FD);
if (EC)
return EC;
+ if (Ret)
+ return std::error_code(errno, std::generic_category());
Result.reset(
new FileOutputBuffer(std::move(MappedFile), FilePath, TempFilePath));
@@ -82,16 +95,10 @@ FileOutputBuffer::create(StringRef FilePath, size_t Size,
return std::error_code();
}
-std::error_code FileOutputBuffer::commit(int64_t NewSmallerSize) {
+std::error_code FileOutputBuffer::commit() {
// Unmap buffer, letting OS flush dirty pages to file on disk.
Region.reset();
- // If requested, resize file as part of commit.
- if ( NewSmallerSize != -1 ) {
- std::error_code EC = sys::fs::resize_file(Twine(TempPath), NewSmallerSize);
- if (EC)
- return EC;
- }
// Rename file to final name.
return sys::fs::rename(Twine(TempPath), Twine(FinalPath));