From b70abe1c5adaf26e8d73d9aa4e5c76ed830cc94e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 30 Dec 2003 07:40:35 +0000 Subject: [PATCH] Use new getFileSize function instead of sys/stat.h directly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10650 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Archive/ArchiveReader.cpp | 12 +++++------- lib/Bytecode/Archive/ArchiveReader.cpp | 12 +++++------- lib/Bytecode/Reader/ArchiveReader.cpp | 12 +++++------- lib/Bytecode/Reader/ReaderWrappers.cpp | 11 ++++------- 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/lib/Archive/ArchiveReader.cpp b/lib/Archive/ArchiveReader.cpp index b147cb3344e..35bbbb97889 100644 --- a/lib/Archive/ArchiveReader.cpp +++ b/lib/Archive/ArchiveReader.cpp @@ -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 @@ -164,17 +164,15 @@ static bool ReadArchiveBuffer(const std::string &ArchiveName, // bool 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!"); + 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) diff --git a/lib/Bytecode/Archive/ArchiveReader.cpp b/lib/Bytecode/Archive/ArchiveReader.cpp index b147cb3344e..35bbbb97889 100644 --- a/lib/Bytecode/Archive/ArchiveReader.cpp +++ b/lib/Bytecode/Archive/ArchiveReader.cpp @@ -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 @@ -164,17 +164,15 @@ static bool ReadArchiveBuffer(const std::string &ArchiveName, // bool 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!"); + 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) diff --git a/lib/Bytecode/Reader/ArchiveReader.cpp b/lib/Bytecode/Reader/ArchiveReader.cpp index b147cb3344e..35bbbb97889 100644 --- a/lib/Bytecode/Reader/ArchiveReader.cpp +++ b/lib/Bytecode/Reader/ArchiveReader.cpp @@ -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 @@ -164,17 +164,15 @@ static bool ReadArchiveBuffer(const std::string &ArchiveName, // bool 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!"); + 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) diff --git a/lib/Bytecode/Reader/ReaderWrappers.cpp b/lib/Bytecode/Reader/ReaderWrappers.cpp index bc3cbbd3309..ef5e70d42b2 100644 --- a/lib/Bytecode/Reader/ReaderWrappers.cpp +++ b/lib/Bytecode/Reader/ReaderWrappers.cpp @@ -21,7 +21,6 @@ #include "Config/fcntl.h" #include "Config/unistd.h" #include "Config/sys/mman.h" -#include #include using namespace llvm; @@ -51,17 +50,15 @@ 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 + "'"); - // 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)