diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-03-15 20:32:14 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-03-15 20:32:14 +0000 |
commit | 1bb30b6f750e2364a68af3b04c76ed26b4f508e8 (patch) | |
tree | 74960b9c621aee287e8d6bf0ae47a290bbdf5e86 /lib/Support/MemoryBuffer.cpp | |
parent | 001903485fc78a4ae5f33420b25db73a22bfdf4a (diff) |
Extend MemoryBuffer::getFile() to take an optional "stat" structure
pointer. If given, the structure will be set with the stat information from
the file actually read.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98575 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/MemoryBuffer.cpp')
-rw-r--r-- | lib/Support/MemoryBuffer.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index eb046d0eaf..345a78c190 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -136,10 +136,11 @@ MemoryBuffer *MemoryBuffer::getNewMemBuffer(size_t Size, /// returns an empty buffer. MemoryBuffer *MemoryBuffer::getFileOrSTDIN(StringRef Filename, std::string *ErrStr, - int64_t FileSize) { + int64_t FileSize, + struct stat *FileInfo) { if (Filename == "-") return getSTDIN(); - return getFile(Filename, ErrStr, FileSize); + return getFile(Filename, ErrStr, FileSize, FileInfo); } //===----------------------------------------------------------------------===// @@ -169,7 +170,7 @@ public: } MemoryBuffer *MemoryBuffer::getFile(StringRef Filename, std::string *ErrStr, - int64_t FileSize) { + int64_t FileSize, struct stat *FileInfo) { int OpenFlags = 0; #ifdef O_BINARY OpenFlags |= O_BINARY; // Open input file in binary mode on win32. @@ -183,15 +184,17 @@ MemoryBuffer *MemoryBuffer::getFile(StringRef Filename, std::string *ErrStr, // If we don't know the file size, use fstat to find out. fstat on an open // file descriptor is cheaper than stat on a random path. - if (FileSize == -1) { - struct stat FileInfo; + if (FileSize == -1 || FileInfo) { + struct stat MyFileInfo; + struct stat *FileInfoPtr = FileInfo? FileInfo : &MyFileInfo; + // TODO: This should use fstat64 when available. - if (fstat(FD, &FileInfo) == -1) { + if (fstat(FD, FileInfoPtr) == -1) { if (ErrStr) *ErrStr = strerror(errno); ::close(FD); return 0; } - FileSize = FileInfo.st_size; + FileSize = FileInfoPtr->st_size; } |