summaryrefslogtreecommitdiff
path: root/lib/Basic/FileManager.cpp
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2010-12-16 03:28:14 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2010-12-16 03:28:14 +0000
commit4eeebc464e1f968d9968a4786c82558f18ac2ed8 (patch)
tree30d74b38fd656ca23cbcb2d274d09bb2746bd397 /lib/Basic/FileManager.cpp
parent66cdf26f28c8f22de9def1d62f7d65447c86b7f1 (diff)
downloadclang-4eeebc464e1f968d9968a4786c82558f18ac2ed8.tar.gz
MemoryBuffer API update.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121956 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/FileManager.cpp')
-rw-r--r--lib/Basic/FileManager.cpp37
1 files changed, 18 insertions, 19 deletions
diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp
index 22a63decb9..488d4c3b8d 100644
--- a/lib/Basic/FileManager.cpp
+++ b/lib/Basic/FileManager.cpp
@@ -401,55 +401,54 @@ void FileManager::FixupRelativePath(llvm::sys::Path &path,
llvm::MemoryBuffer *FileManager::
getBufferForFile(const FileEntry *Entry, std::string *ErrorStr) {
+ llvm::OwningPtr<llvm::MemoryBuffer> Result;
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, ec,
- Entry->getSize());
- if (Buf == 0 && ErrorStr)
+ ec = llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, Result,
+ Entry->getSize());
+ if (ErrorStr)
*ErrorStr = ec.message();
// getOpenFile will have closed the file descriptor, don't reuse or
// reclose it.
Entry->FD = -1;
- return Buf;
+ return Result.take();
}
// Otherwise, open the file.
- llvm::MemoryBuffer *res =
- llvm::MemoryBuffer::getFile(Filename, ec, Entry->getSize());
- if (res == 0 && ErrorStr)
+ ec = llvm::MemoryBuffer::getFile(Filename, Result, Entry->getSize());
+ if (ec && ErrorStr)
*ErrorStr = ec.message();
- return res;
+ return Result.take();
}
llvm::sys::Path FilePath(Entry->getName());
FixupRelativePath(FilePath, FileSystemOpts);
- llvm::MemoryBuffer *res =
- llvm::MemoryBuffer::getFile(FilePath.c_str(), ec, Entry->getSize());
- if (res == 0 && ErrorStr)
+ ec = llvm::MemoryBuffer::getFile(FilePath.c_str(), Result, Entry->getSize());
+ if (ec && ErrorStr)
*ErrorStr = ec.message();
- return res;
+ return Result.take();
}
llvm::MemoryBuffer *FileManager::
getBufferForFile(llvm::StringRef Filename, std::string *ErrorStr) {
+ llvm::OwningPtr<llvm::MemoryBuffer> Result;
llvm::error_code ec;
if (FileSystemOpts.WorkingDir.empty()) {
- llvm::MemoryBuffer *res = llvm::MemoryBuffer::getFile(Filename, ec);
- if (res == 0 && ErrorStr)
+ ec = llvm::MemoryBuffer::getFile(Filename, Result);
+ if (ec && ErrorStr)
*ErrorStr = ec.message();
- return res;
+ return Result.take();
}
llvm::sys::Path FilePath(Filename);
FixupRelativePath(FilePath, FileSystemOpts);
- llvm::MemoryBuffer *res = llvm::MemoryBuffer::getFile(FilePath.c_str(), ec);
- if (res == 0 && ErrorStr)
+ ec = llvm::MemoryBuffer::getFile(FilePath.c_str(), Result);
+ if (ec && ErrorStr)
*ErrorStr = ec.message();
- return res;
+ return Result.take();
}
/// getStatValue - Get the 'stat' information for the specified path, using the