diff options
| author | Chris Lattner <sabre@nondot.org> | 2004-05-28 00:24:41 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2004-05-28 00:24:41 +0000 |
| commit | 90634616035a9ebcf2f5b1eb57ce2c7b98a0a227 (patch) | |
| tree | d2af5118690e1030d13acb14b93b62123a84b72b /llvm/lib/Bytecode/Reader/ArchiveReader.cpp | |
| parent | 0e713bc208951b2bfe497b7d4d9aae1645ac9f52 (diff) | |
| download | bcm5719-llvm-90634616035a9ebcf2f5b1eb57ce2c7b98a0a227.tar.gz bcm5719-llvm-90634616035a9ebcf2f5b1eb57ce2c7b98a0a227.zip | |
Use the new FileUtilities.h API for mapping a file into an address
space
llvm-svn: 13864
Diffstat (limited to 'llvm/lib/Bytecode/Reader/ArchiveReader.cpp')
| -rw-r--r-- | llvm/lib/Bytecode/Reader/ArchiveReader.cpp | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/llvm/lib/Bytecode/Reader/ArchiveReader.cpp b/llvm/lib/Bytecode/Reader/ArchiveReader.cpp index 8671c422a1e..1e2d2b47131 100644 --- a/llvm/lib/Bytecode/Reader/ArchiveReader.cpp +++ b/llvm/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 <cstdlib> using namespace llvm; @@ -166,25 +164,21 @@ static bool ReadArchiveBuffer(const std::string &ArchiveName, // bool llvm::ReadArchiveFile(const std::string &Filename, std::vector<Module*> &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()) { |

