aboutsummaryrefslogtreecommitdiffstats
path: root/lib/System
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-08-01 17:51:09 +0000
committerChris Lattner <sabre@nondot.org>2006-08-01 17:51:09 +0000
commitc7c453a845dcb786bb85e9c0e17d0b56c2a8b155 (patch)
tree9fb1be8fe50b7d0a6169bdf08e7d140ba4bed2b1 /lib/System
parent3336aa056f050770374ac9c92bd23a435dd5d7cc (diff)
downloadexternal_llvm-c7c453a845dcb786bb85e9c0e17d0b56c2a8b155.zip
external_llvm-c7c453a845dcb786bb85e9c0e17d0b56c2a8b155.tar.gz
external_llvm-c7c453a845dcb786bb85e9c0e17d0b56c2a8b155.tar.bz2
elimiante some syscalls
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29442 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System')
-rw-r--r--lib/System/Unix/Path.inc27
-rw-r--r--lib/System/Win32/Path.inc16
2 files changed, 20 insertions, 23 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
index f26315c..41349d9 100644
--- a/lib/System/Unix/Path.inc
+++ b/lib/System/Unix/Path.inc
@@ -241,7 +241,7 @@ Path::isFile() const {
if (!exists())
return false;
struct stat buf;
- if (0 != stat(path.c_str(), &buf)) {
+ if (stat(path.c_str(), &buf) != 0) {
ThrowErrno(path + ": can't determine type of path object: ");
}
return S_ISREG(buf.st_mode);
@@ -286,12 +286,10 @@ Path::getBasename() const {
}
bool Path::hasMagicNumber(const std::string &Magic) const {
- if (!isFile())
- return false;
size_t len = Magic.size();
assert(len < 1024 && "Request for magic string too long");
char* buf = (char*) alloca(1 + len);
- int fd = ::open(path.c_str(),O_RDONLY);
+ int fd = ::open(path.c_str(), O_RDONLY);
if (fd < 0)
return false;
size_t read_len = ::read(fd, buf, len);
@@ -303,11 +301,9 @@ bool Path::hasMagicNumber(const std::string &Magic) const {
}
bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
- if (!isFile())
- return false;
assert(len < 1024 && "Request for magic string too long");
char* buf = (char*) alloca(1 + len);
- int fd = ::open(path.c_str(),O_RDONLY);
+ int fd = ::open(path.c_str(), O_RDONLY);
if (fd < 0)
return false;
ssize_t bytes_read = ::read(fd, buf, len);
@@ -322,11 +318,9 @@ bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
bool
Path::isBytecodeFile() const {
- if (!isFile())
- return false;
- char buffer[ 4];
+ char buffer[4];
buffer[0] = 0;
- int fd = ::open(path.c_str(),O_RDONLY);
+ int fd = ::open(path.c_str(), O_RDONLY);
if (fd < 0)
return false;
ssize_t bytes_read = ::read(fd, buffer, 4);
@@ -335,7 +329,7 @@ Path::isBytecodeFile() const {
return false;
return (buffer[0] == 'l' && buffer[1] == 'l' && buffer[2] == 'v' &&
- (buffer[3] == 'c' || buffer[3] == 'm'));
+ (buffer[3] == 'c' || buffer[3] == 'm'));
}
bool
@@ -605,14 +599,17 @@ Path::createTemporaryFileOnDisk(bool reuse_current) {
bool
Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
- // Make sure we're dealing with a directory.
- if (isFile()) {
+ FileStatus Status;
+ if (getFileStatus(Status, ErrStr))
+ return true;
+
+ if (Status.isFile) {
if (unlink(path.c_str()) != 0)
return GetErrno(path + ": can't destroy file", ErrStr);
return false;
}
- if (!isDirectory()) {
+ if (!Status.isDir) {
if (ErrStr) *ErrStr = "not a file or directory";
return true;
}
diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc
index 7b74746..73432ba 100644
--- a/lib/System/Win32/Path.inc
+++ b/lib/System/Win32/Path.inc
@@ -281,8 +281,6 @@ bool Path::hasMagicNumber(const std::string &Magic) const {
bool
Path::isBytecodeFile() const {
- if (!isFile())
- return false;
std::string actualMagic;
if (!getMagicNumber(actualMagic, 4))
return false;
@@ -574,12 +572,16 @@ Path::createFileOnDisk() {
bool
Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
- if (isFile()) {
+ FileStatus Status;
+ if (getFileStatus(Status, ErrStr))
+ return true;
+
+ if (Status.isFile) {
DWORD attr = GetFileAttributes(path.c_str());
// If it doesn't exist, we're done.
if (attr == INVALID_FILE_ATTRIBUTES)
- return false;
+ return true;
// Read-only files cannot be deleted on Windows. Must remove the read-only
// attribute first.
@@ -590,8 +592,8 @@ Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
if (!DeleteFile(path.c_str()))
ThrowError(path + ": Can't destroy file: ");
- return true;
- } else if (isDirectory()) {
+ return false;
+ } else if (Status.isDir) {
// If it doesn't exist, we're done.
if (!exists())
return false;
@@ -657,8 +659,6 @@ Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
}
bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
- if (!isFile())
- return false;
assert(len < 1024 && "Request for magic string too long");
char* buf = (char*) alloca(1 + len);