diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-11-22 12:31:53 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-11-22 12:31:53 +0000 |
commit | 5745fbce1674b29f4dce6b6e31556c4c1e83dc89 (patch) | |
tree | a5aaefd6d9fb122e4f744a855d20e57df129b7e9 /lib/Support/MemoryBuffer.cpp | |
parent | f264568bae482601431e4ac923172fa3671eb9e7 (diff) |
Add configure checking for pread(2) and use it to save a syscall when reading files.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145061 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 580338117b..1a409720c0 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -14,6 +14,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Config/config.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/Errno.h" #include "llvm/Support/Path.h" @@ -320,11 +321,17 @@ error_code MemoryBuffer::getOpenFile(int FD, const char *Filename, char *BufPtr = const_cast<char*>(SB->getBufferStart()); size_t BytesLeft = MapSize; +#ifndef HAVE_PREAD if (lseek(FD, Offset, SEEK_SET) == -1) return error_code(errno, posix_category()); +#endif while (BytesLeft) { +#ifdef HAVE_PREAD + ssize_t NumRead = ::pread(FD, BufPtr, BytesLeft, MapSize-BytesLeft+Offset); +#else ssize_t NumRead = ::read(FD, BufPtr, BytesLeft); +#endif if (NumRead == -1) { if (errno == EINTR) continue; |