diff options
author | Stephen Hines <srhines@google.com> | 2015-03-23 12:10:34 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2015-03-23 12:10:34 -0700 |
commit | ebe69fe11e48d322045d5949c83283927a0d790b (patch) | |
tree | c92f1907a6b8006628a4b01615f38264d29834ea /lib/Support/FileOutputBuffer.cpp | |
parent | b7d2e72b02a4cb8034f32f8247a2558d2434e121 (diff) | |
download | external_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.zip external_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.tar.gz external_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.tar.bz2 |
Update aosp/master LLVM for rebase to r230699.
Change-Id: I2b5be30509658cb8266be782de0ab24f9099f9b9
Diffstat (limited to 'lib/Support/FileOutputBuffer.cpp')
-rw-r--r-- | lib/Support/FileOutputBuffer.cpp | 27 |
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)); |