[llvm-commits] CVS: llvm/lib/Bytecode/Reader/ArchiveReader.cpp ReaderWrappers.cpp
Chris Lattner
lattner at cs.uiuc.edu
Tue Dec 30 01:41:00 PST 2003
Changes in directory llvm/lib/Bytecode/Reader:
ArchiveReader.cpp updated: 1.13 -> 1.14
ReaderWrappers.cpp updated: 1.20 -> 1.21
---
Log message:
Use new getFileSize function instead of sys/stat.h directly.
---
Diffs of the changes: (+9 -14)
Index: llvm/lib/Bytecode/Reader/ArchiveReader.cpp
diff -u llvm/lib/Bytecode/Reader/ArchiveReader.cpp:1.13 llvm/lib/Bytecode/Reader/ArchiveReader.cpp:1.14
--- llvm/lib/Bytecode/Reader/ArchiveReader.cpp:1.13 Mon Dec 22 10:22:49 2003
+++ llvm/lib/Bytecode/Reader/ArchiveReader.cpp Tue Dec 30 01:40:35 2003
@@ -18,7 +18,7 @@
#include "llvm/Bytecode/Reader.h"
#include "llvm/Module.h"
-#include "Config/sys/stat.h"
+#include "Support/FileUtilities.h"
#include "Config/sys/mman.h"
#include "Config/fcntl.h"
#include <cstdlib>
@@ -164,17 +164,15 @@
//
bool 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!");
+
int FD = open(Filename.c_str(), O_RDONLY);
if (FD == -1)
return Error(ErrorStr, "Error opening file!");
- // Stat the file to get its length...
- struct stat StatBuf;
- if (fstat(FD, &StatBuf) == -1 || StatBuf.st_size == 0)
- return Error(ErrorStr, "Error stat'ing file!");
-
// mmap in the file all at once...
- int Length = StatBuf.st_size;
unsigned char *Buffer = (unsigned char*)mmap(0, Length, PROT_READ,
MAP_PRIVATE, FD, 0);
if (Buffer == (unsigned char*)MAP_FAILED)
Index: llvm/lib/Bytecode/Reader/ReaderWrappers.cpp
diff -u llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.20 llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.21
--- llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.20 Mon Dec 29 15:35:05 2003
+++ llvm/lib/Bytecode/Reader/ReaderWrappers.cpp Tue Dec 30 01:40:35 2003
@@ -21,7 +21,6 @@
#include "Config/fcntl.h"
#include "Config/unistd.h"
#include "Config/sys/mman.h"
-#include <sys/stat.h>
#include <cerrno>
using namespace llvm;
@@ -51,17 +50,15 @@
}
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 + "'");
- // Stat the file to get its length...
- struct stat StatBuf;
- if (fstat(FD, &StatBuf) == -1 || StatBuf.st_size == 0)
- throw ErrnoMessage(errno, "stat '" + Filename + "'");
-
// mmap in the file all at once...
- Length = StatBuf.st_size;
Buffer = (unsigned char*)mmap(0, Length, PROT_READ, MAP_PRIVATE, FD, 0);
if (Buffer == (unsigned char*)MAP_FAILED)
More information about the llvm-commits
mailing list