summaryrefslogtreecommitdiff
path: root/lib/Support/MemoryBuffer.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-07-18 03:04:20 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-07-18 03:04:20 +0000
commit1ceefa6aa3fa82f7dda1ac070d133d3b1102bf93 (patch)
tree7f59d13ce715113c1f43d3a1b9d8a89d1cb0bbf8 /lib/Support/MemoryBuffer.cpp
parent60f18ad8a5fa7d5b008a1fecf9a79b68883ca192 (diff)
downloadllvm-1ceefa6aa3fa82f7dda1ac070d133d3b1102bf93.tar.gz
llvm-1ceefa6aa3fa82f7dda1ac070d133d3b1102bf93.tar.bz2
llvm-1ceefa6aa3fa82f7dda1ac070d133d3b1102bf93.tar.xz
Convert two uses if fstat with sys::fs::status.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186560 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/MemoryBuffer.cpp')
-rw-r--r--lib/Support/MemoryBuffer.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp
index be1d9c7874..051d64b038 100644
--- a/lib/Support/MemoryBuffer.cpp
+++ b/lib/Support/MemoryBuffer.cpp
@@ -283,12 +283,11 @@ static bool shouldUseMmap(int FD,
// FIXME: this chunk of code is duplicated, but it avoids a fstat when
// RequiresNullTerminator = false and MapSize != -1.
if (FileSize == size_t(-1)) {
- struct stat FileInfo;
- // TODO: This should use fstat64 when available.
- if (fstat(FD, &FileInfo) == -1) {
- return error_code(errno, posix_category());
- }
- FileSize = FileInfo.st_size;
+ sys::fs::file_status Status;
+ error_code EC = sys::fs::status(FD, Status);
+ if (EC)
+ return EC;
+ FileSize = Status.getSize();
}
// If we need a null terminator and the end of the map is inside the file,
@@ -318,20 +317,20 @@ error_code MemoryBuffer::getOpenFile(int FD, const char *Filename,
// 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 == uint64_t(-1)) {
- struct stat FileInfo;
- // TODO: This should use fstat64 when available.
- if (fstat(FD, &FileInfo) == -1) {
- return error_code(errno, posix_category());
- }
+ sys::fs::file_status Status;
+ error_code EC = sys::fs::status(FD, Status);
+ if (EC)
+ return EC;
// If this not a file or a block device (e.g. it's a named pipe
// or character device), we can't trust the size. Create the memory
// buffer by copying off the stream.
- if (!S_ISREG(FileInfo.st_mode) && !S_ISBLK(FileInfo.st_mode)) {
+ sys::fs::file_type Type = Status.type();
+ if (Type != sys::fs::file_type::regular_file &&
+ Type != sys::fs::file_type::block_file)
return getMemoryBufferForStream(FD, Filename, result);
- }
- FileSize = FileInfo.st_size;
+ FileSize = Status.getSize();
}
MapSize = FileSize;
}