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
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp
index da46853..5b701a5 100644
--- a/lib/Support/MemoryBuffer.cpp
+++ b/lib/Support/MemoryBuffer.cpp
@@ -187,6 +187,7 @@
 
 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 @@
     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