aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode/Reader/ReaderWrappers.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-05-28 00:24:41 +0000
committerChris Lattner <sabre@nondot.org>2004-05-28 00:24:41 +0000
commitfb777c270bac4b95b739dad552c5ab8f5aa2aef4 (patch)
tree21f1db5e63b51de008c362a2023b1f38ddd1d0b8 /lib/Bytecode/Reader/ReaderWrappers.cpp
parenteb082995180756068af35bb826a9017975d87a51 (diff)
Use the new FileUtilities.h API for mapping a file into an address
space git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13864 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Reader/ReaderWrappers.cpp')
-rw-r--r--lib/Bytecode/Reader/ReaderWrappers.cpp24
1 files changed, 6 insertions, 18 deletions
diff --git a/lib/Bytecode/Reader/ReaderWrappers.cpp b/lib/Bytecode/Reader/ReaderWrappers.cpp
index ef5e70d42b..be1541707e 100644
--- a/lib/Bytecode/Reader/ReaderWrappers.cpp
+++ b/lib/Bytecode/Reader/ReaderWrappers.cpp
@@ -18,9 +18,7 @@
#include "llvm/Instructions.h"
#include "Support/FileUtilities.h"
#include "Support/StringExtras.h"
-#include "Config/fcntl.h"
#include "Config/unistd.h"
-#include "Config/sys/mman.h"
#include <cerrno>
using namespace llvm;
@@ -34,7 +32,7 @@ namespace {
class BytecodeFileReader : public BytecodeParser {
private:
unsigned char *Buffer;
- int Length;
+ unsigned Length;
BytecodeFileReader(const BytecodeFileReader&); // Do not implement
void operator=(const BytecodeFileReader &BFR); // Do not implement
@@ -50,32 +48,22 @@ static std::string ErrnoMessage (int savedErrNum, std::string descr) {
}
BytecodeFileReader::BytecodeFileReader(const std::string &Filename) {
- Length = getFileSize(Filename);
- if (Length == -1)
- throw ErrnoMessage(errno, "stat '" + Filename + "'");
-
- FDHandle FD(open(Filename.c_str(), O_RDONLY));
- if (FD == -1)
- throw ErrnoMessage(errno, "open '" + Filename + "'");
-
- // mmap in the file all at once...
- Buffer = (unsigned char*)mmap(0, Length, PROT_READ, MAP_PRIVATE, FD, 0);
-
- if (Buffer == (unsigned char*)MAP_FAILED)
- throw ErrnoMessage(errno, "map '" + Filename + "' into memory");
+ Buffer = (unsigned char*)ReadFileIntoAddressSpace(Filename, Length);
+ if (Buffer == 0)
+ throw "Error reading file '" + Filename + "'.";
try {
// Parse the bytecode we mmapped in
ParseBytecode(Buffer, Length, Filename);
} catch (...) {
- munmap((char*)Buffer, Length);
+ UnmapFileFromAddressSpace(Buffer, Length);
throw;
}
}
BytecodeFileReader::~BytecodeFileReader() {
// Unmmap the bytecode...
- munmap((char*)Buffer, Length);
+ UnmapFileFromAddressSpace(Buffer, Length);
}
//===----------------------------------------------------------------------===//