X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FFileOutputBuffer.cpp;h=94bcdc58a8062d2c2a9179a3a6811044b40fa3bf;hb=dee5e2cf7fa5cfc9c9407d66dae9169586041a51;hp=ed084faed789e2d11c629ff6dfd1a6cafaacfba8;hpb=73e97d0f48cf9ed3093019064f6340617ac8de9e;p=oota-llvm.git diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp index ed084faed78..94bcdc58a80 100644 --- a/lib/Support/FileOutputBuffer.cpp +++ b/lib/Support/FileOutputBuffer.cpp @@ -11,11 +11,11 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/Errc.h" #include "llvm/Support/FileOutputBuffer.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/system_error.h" +#include using llvm::sys::fs::mapped_file_region; @@ -28,17 +28,16 @@ FileOutputBuffer::FileOutputBuffer(mapped_file_region * R, } FileOutputBuffer::~FileOutputBuffer() { - bool Existed; - sys::fs::remove(Twine(TempPath), Existed); + sys::fs::remove(Twine(TempPath)); } -error_code FileOutputBuffer::create(StringRef FilePath, - size_t Size, - OwningPtr &Result, - unsigned Flags) { +std::error_code +FileOutputBuffer::create(StringRef FilePath, size_t Size, + std::unique_ptr &Result, + unsigned Flags) { // If file already exists, it must be a regular file (to be mappable). sys::fs::file_status Stat; - error_code EC = sys::fs::status(FilePath, Stat); + std::error_code EC = sys::fs::status(FilePath, Stat); switch (Stat.type()) { case sys::fs::file_type::file_not_found: // If file does not exist, we'll create one. @@ -57,8 +56,7 @@ error_code FileOutputBuffer::create(StringRef FilePath, } // Delete target file. - bool Existed; - EC = sys::fs::remove(FilePath, Existed); + EC = sys::fs::remove(FilePath); if (EC) return EC; @@ -75,25 +73,25 @@ error_code FileOutputBuffer::create(StringRef FilePath, if (EC) return EC; - OwningPtr MappedFile(new mapped_file_region( + std::unique_ptr MappedFile(new mapped_file_region( FD, true, mapped_file_region::readwrite, Size, 0, EC)); if (EC) return EC; Result.reset(new FileOutputBuffer(MappedFile.get(), FilePath, TempFilePath)); if (Result) - MappedFile.take(); + MappedFile.release(); - return error_code::success(); + return std::error_code(); } -error_code FileOutputBuffer::commit(int64_t NewSmallerSize) { +std::error_code FileOutputBuffer::commit(int64_t NewSmallerSize) { // Unmap buffer, letting OS flush dirty pages to file on disk. - Region.reset(0); + Region.reset(); // If requested, resize file as part of commit. if ( NewSmallerSize != -1 ) { - error_code EC = sys::fs::resize_file(Twine(TempPath), NewSmallerSize); + std::error_code EC = sys::fs::resize_file(Twine(TempPath), NewSmallerSize); if (EC) return EC; }