mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-01 15:17:25 +00:00
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
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user