llvm.org GIT mirror llvm / 531b802
Use fileutilities instead of mmap directly git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13865 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 15 years ago
1 changed file(s) with 2 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
3636 /// OpenFile - mmap the specified file into the address space for reading, and
3737 /// return the length and address of the buffer.
3838 static void OpenFile(const std::string &Filename, unsigned &Len, char* &BufPtr){
39 int FD = open(Filename.c_str(), O_RDONLY);
40 if (FD == -1 || (Len = getFileSize(Filename)) == ~0U) {
39 BufPtr = (char*)ReadFileIntoAddressSpace(Filename, Len);
40 if (BufPtr == 0) {
4141 std::cerr << "Error: cannot open file '" << Filename << "'\n";
4242 exit(2);
4343 }
44
45 // mmap in the file all at once...
46 BufPtr = (char*)mmap(0, Len, PROT_READ, MAP_PRIVATE, FD, 0);
47
48 if (BufPtr == (char*)MAP_FAILED) {
49 std::cerr << "Error: cannot open file '" << Filename << "'\n";
50 exit(2);
51 }
52
53 // If mmap decided that the files were empty, it might have returned a
54 // null pointer. If so, make a new, fake pointer -- it shouldn't matter
55 // what it contains, because Len is 0, and it should never be read.
56 if (BufPtr == 0 && Len == 0)
57 BufPtr = new char[1];
5844 }
5945
6046 static bool isNumberChar(char C) {