From fb777c270bac4b95b739dad552c5ab8f5aa2aef4 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 28 May 2004 00:24:41 +0000 Subject: 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 --- lib/Bytecode/Reader/ArchiveReader.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'lib/Bytecode/Reader/ArchiveReader.cpp') diff --git a/lib/Bytecode/Reader/ArchiveReader.cpp b/lib/Bytecode/Reader/ArchiveReader.cpp index 8671c422a1..1e2d2b4713 100644 --- a/lib/Bytecode/Reader/ArchiveReader.cpp +++ b/lib/Bytecode/Reader/ArchiveReader.cpp @@ -19,8 +19,6 @@ #include "llvm/Bytecode/Reader.h" #include "llvm/Module.h" #include "Support/FileUtilities.h" -#include "Config/sys/mman.h" -#include "Config/fcntl.h" #include using namespace llvm; @@ -166,25 +164,21 @@ static bool ReadArchiveBuffer(const std::string &ArchiveName, // bool llvm::ReadArchiveFile(const std::string &Filename, std::vector &Objects,std::string *ErrorStr){ - int Length = getFileSize(Filename); - if (Length == -1) - return Error(ErrorStr, "Error getting file length!"); + unsigned Length; - int FD = open(Filename.c_str(), O_RDONLY); - if (FD == -1) - return Error(ErrorStr, "Error opening file!"); - // mmap in the file all at once... - unsigned char *Buffer = (unsigned char*)mmap(0, Length, PROT_READ, - MAP_PRIVATE, FD, 0); - if (Buffer == (unsigned char*)MAP_FAILED) - return Error(ErrorStr, "Error mmapping file!"); + unsigned char *Buffer = + (unsigned char*)ReadFileIntoAddressSpace(Filename, Length); + if (Buffer == 0) { + if (ErrorStr) *ErrorStr = "Error reading file '" + Filename + "'!"; + return true; + } // Parse the archive files we mmap'ped in bool Result = ReadArchiveBuffer(Filename, Buffer, Length, Objects, ErrorStr); // Unmmap the archive... - munmap((char*)Buffer, Length); + UnmapFileFromAddressSpace(Buffer, Length); if (Result) // Free any loaded objects while (!Objects.empty()) { -- cgit v1.2.3