diff options
author | Chris Lattner <sabre@nondot.org> | 2010-11-23 22:20:27 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-11-23 22:20:27 +0000 |
commit | 7cf705461cfdca5dd5b48a5065f8e24a1ce8c8c4 (patch) | |
tree | 748c87754359afa56af11389d94c0d8148be95ab /lib/Support/MemoryBuffer.cpp | |
parent | 67ff104e7e42fe72ce0f20d6eeadb5ca5c45d119 (diff) |
add a MemoryBuffer::getOpenFile method, which turns an open
file descriptor into a MemoryBuffer (and closes the FD).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120065 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/MemoryBuffer.cpp')
-rw-r--r-- | lib/Support/MemoryBuffer.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index da4685309d..5b701a5c60 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -187,6 +187,7 @@ public: MemoryBuffer *MemoryBuffer::getFile(StringRef Filename, std::string *ErrStr, int64_t FileSize) { + // Ensure the path is null terminated. SmallString<256> PathBuf(Filename.begin(), Filename.end()); return MemoryBuffer::getFile(PathBuf.c_str(), ErrStr, FileSize); } @@ -202,6 +203,12 @@ MemoryBuffer *MemoryBuffer::getFile(const char *Filename, std::string *ErrStr, if (ErrStr) *ErrStr = sys::StrError(); return 0; } + + return getOpenFile(FD, Filename, ErrStr, FileSize); +} + +MemoryBuffer *MemoryBuffer::getOpenFile(int FD, const char *Filename, + std::string *ErrStr, int64_t FileSize) { FileCloser FC(FD); // Close FD on return. // If we don't know the file size, use fstat to find out. fstat on an open |