From 67c32a98315f785a9ec9d531c1f571a0196c7463 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 18 Jan 2015 16:17:27 +0000 Subject: Vendor import of llvm RELEASE_360/rc1 tag r226102 (effectively, 3.6.0 RC1): https://llvm.org/svn/llvm-project/llvm/tags/RELEASE_360/rc1@226102 --- lib/Support/FileOutputBuffer.cpp | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'lib/Support/FileOutputBuffer.cpp') diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp index 94bcdc58a8062..b176a8b45ab30 100644 --- a/lib/Support/FileOutputBuffer.cpp +++ b/lib/Support/FileOutputBuffer.cpp @@ -12,20 +12,24 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Errc.h" -#include "llvm/Support/FileOutputBuffer.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/Support/FileOutputBuffer.h" #include "llvm/Support/raw_ostream.h" #include +#if !defined(_MSC_VER) && !defined(__MINGW32__) +#include +#else +#include +#endif + using llvm::sys::fs::mapped_file_region; namespace llvm { -FileOutputBuffer::FileOutputBuffer(mapped_file_region * R, +FileOutputBuffer::FileOutputBuffer(std::unique_ptr R, StringRef Path, StringRef TmpPath) - : Region(R) - , FinalPath(Path) - , TempPath(TmpPath) { -} + : Region(std::move(R)), FinalPath(Path), TempPath(TmpPath) {} FileOutputBuffer::~FileOutputBuffer() { sys::fs::remove(Twine(TempPath)); @@ -73,28 +77,28 @@ FileOutputBuffer::create(StringRef FilePath, size_t Size, if (EC) return EC; - std::unique_ptr MappedFile(new mapped_file_region( - FD, true, mapped_file_region::readwrite, Size, 0, EC)); + EC = sys::fs::resize_file(FD, Size); if (EC) return EC; - Result.reset(new FileOutputBuffer(MappedFile.get(), FilePath, TempFilePath)); - if (Result) - MappedFile.release(); + auto MappedFile = llvm::make_unique( + 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)); 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)); -- cgit v1.2.3