summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/FileManager.cpp
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2010-12-09 17:36:38 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2010-12-09 17:36:38 +0000
commitf25faaaffbd9c6d3ffeccb333d0338e5bcb796b1 (patch)
tree70ae0540bfd7a3e2623f0d9c62ff3670d8d31a1d /clang/lib/Basic/FileManager.cpp
parentd47180e45e96411c69dad778752988fed336ac4f (diff)
downloadbcm5719-llvm-f25faaaffbd9c6d3ffeccb333d0338e5bcb796b1.tar.gz
bcm5719-llvm-f25faaaffbd9c6d3ffeccb333d0338e5bcb796b1.zip
Use error_code instead of std::string* for MemoryBuffer.
llvm-svn: 121378
Diffstat (limited to 'clang/lib/Basic/FileManager.cpp')
-rw-r--r--clang/lib/Basic/FileManager.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 0e47e5e3a61..22a63decb9f 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/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
OpenPOWER on IntegriCloud