diff options
Diffstat (limited to 'contrib/llvm/lib/Support/FileOutputBuffer.cpp')
-rw-r--r-- | contrib/llvm/lib/Support/FileOutputBuffer.cpp | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/contrib/llvm/lib/Support/FileOutputBuffer.cpp b/contrib/llvm/lib/Support/FileOutputBuffer.cpp index 94bcdc5..b176a8b 100644 --- a/contrib/llvm/lib/Support/FileOutputBuffer.cpp +++ b/contrib/llvm/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 <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 { -FileOutputBuffer::FileOutputBuffer(mapped_file_region * R, +FileOutputBuffer::FileOutputBuffer(std::unique_ptr<mapped_file_region> 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<mapped_file_region> 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<mapped_file_region>( + 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)); |