diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-09 17:36:38 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-09 17:36:38 +0000 |
commit | 3a321e23f66128dbb986343927456ff6702af617 (patch) | |
tree | 058f1f5a8a7e4044f51dfbdc62a46b80693b94a9 /lib/Basic/FileManager.cpp | |
parent | 8f1509446fc51db0473ea1241910c06353a153b8 (diff) |
Use error_code instead of std::string* for MemoryBuffer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121378 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/FileManager.cpp')
-rw-r--r-- | lib/Basic/FileManager.cpp | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp index 0e47e5e3a6..22a63decb9 100644 --- a/lib/Basic/FileManager.cpp +++ b/lib/Basic/FileManager.cpp @@ -24,6 +24,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/Path.h" +#include "llvm/Support/system_error.h" #include "llvm/Config/config.h" #include <map> #include <set> @@ -400,13 +401,16 @@ void FileManager::FixupRelativePath(llvm::sys::Path &path, llvm::MemoryBuffer *FileManager:: getBufferForFile(const FileEntry *Entry, std::string *ErrorStr) { + llvm::error_code ec; if (FileSystemOpts.WorkingDir.empty()) { const char *Filename = Entry->getName(); // If the file is already open, use the open file descriptor. if (Entry->FD != -1) { llvm::MemoryBuffer *Buf = - llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, ErrorStr, + llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, ec, Entry->getSize()); + if (Buf == 0 && ErrorStr) + *ErrorStr = ec.message(); // getOpenFile will have closed the file descriptor, don't reuse or // reclose it. Entry->FD = -1; @@ -414,23 +418,38 @@ getBufferForFile(const FileEntry *Entry, std::string *ErrorStr) { } // Otherwise, open the file. - return llvm::MemoryBuffer::getFile(Filename, ErrorStr, Entry->getSize()); + llvm::MemoryBuffer *res = + llvm::MemoryBuffer::getFile(Filename, ec, Entry->getSize()); + if (res == 0 && ErrorStr) + *ErrorStr = ec.message(); + return res; } llvm::sys::Path FilePath(Entry->getName()); FixupRelativePath(FilePath, FileSystemOpts); - return llvm::MemoryBuffer::getFile(FilePath.c_str(), ErrorStr, - Entry->getSize()); + llvm::MemoryBuffer *res = + llvm::MemoryBuffer::getFile(FilePath.c_str(), ec, Entry->getSize()); + if (res == 0 && ErrorStr) + *ErrorStr = ec.message(); + return res; } llvm::MemoryBuffer *FileManager:: getBufferForFile(llvm::StringRef Filename, std::string *ErrorStr) { - if (FileSystemOpts.WorkingDir.empty()) - return llvm::MemoryBuffer::getFile(Filename, ErrorStr); - + llvm::error_code ec; + if (FileSystemOpts.WorkingDir.empty()) { + llvm::MemoryBuffer *res = llvm::MemoryBuffer::getFile(Filename, ec); + if (res == 0 && ErrorStr) + *ErrorStr = ec.message(); + return res; + } + llvm::sys::Path FilePath(Filename); FixupRelativePath(FilePath, FileSystemOpts); - return llvm::MemoryBuffer::getFile(FilePath.c_str(), ErrorStr); + llvm::MemoryBuffer *res = llvm::MemoryBuffer::getFile(FilePath.c_str(), ec); + if (res == 0 && ErrorStr) + *ErrorStr = ec.message(); + return res; } /// getStatValue - Get the 'stat' information for the specified path, using the |