aboutsummaryrefslogtreecommitdiffstats
path: root/lib/System/Unix
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-12-11 00:14:15 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-12-11 00:14:15 +0000
commit1fce09125cb46c91407668ca29915c450a482811 (patch)
tree9a221a439d7dc3ec57b8fa6cf345b90b6198d883 /lib/System/Unix
parent357cf5439a5e0ad49245dc75798b6490d67834fd (diff)
downloadexternal_llvm-1fce09125cb46c91407668ca29915c450a482811.zip
external_llvm-1fce09125cb46c91407668ca29915c450a482811.tar.gz
external_llvm-1fce09125cb46c91407668ca29915c450a482811.tar.bz2
Path::get -> Path::toString
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18785 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Unix')
-rw-r--r--lib/System/Unix/MappedFile.cpp8
-rw-r--r--lib/System/Unix/MappedFile.inc8
-rw-r--r--lib/System/Unix/Path.cpp15
-rw-r--r--lib/System/Unix/Path.inc15
-rw-r--r--lib/System/Unix/Program.cpp11
-rw-r--r--lib/System/Unix/Program.inc11
-rw-r--r--lib/System/Unix/Signals.cpp2
-rw-r--r--lib/System/Unix/Signals.inc2
8 files changed, 42 insertions, 30 deletions
diff --git a/lib/System/Unix/MappedFile.cpp b/lib/System/Unix/MappedFile.cpp
index 0e03a04..1c9622d 100644
--- a/lib/System/Unix/MappedFile.cpp
+++ b/lib/System/Unix/MappedFile.cpp
@@ -44,17 +44,17 @@ void MappedFile::initialize() {
if (info_->fd_ < 0) {
delete info_;
info_ = 0;
- ThrowErrno(std::string("Can't open file: ") + path_.get());
+ ThrowErrno(std::string("Can't open file: ") + path_.toString());
}
struct stat sbuf;
if(::fstat(info_->fd_, &info_->sbuf_) < 0) {
::close(info_->fd_);
delete info_;
info_ = 0;
- ThrowErrno(std::string("Can't stat file: ") + path_.get());
+ ThrowErrno(std::string("Can't stat file: ") + path_.toString());
}
} else {
- throw std::string("Can't open file: ") + path_.get();
+ throw std::string("Can't open file: ") + path_.toString();
}
}
@@ -103,7 +103,7 @@ void* MappedFile::map() {
base_ = ::mmap(0, map_size, prot, flags, info_->fd_, 0);
if (base_ == MAP_FAILED)
- ThrowErrno(std::string("Can't map file:") + path_.get());
+ ThrowErrno(std::string("Can't map file:") + path_.toString());
}
return base_;
}
diff --git a/lib/System/Unix/MappedFile.inc b/lib/System/Unix/MappedFile.inc
index 0e03a04..1c9622d 100644
--- a/lib/System/Unix/MappedFile.inc
+++ b/lib/System/Unix/MappedFile.inc
@@ -44,17 +44,17 @@ void MappedFile::initialize() {
if (info_->fd_ < 0) {
delete info_;
info_ = 0;
- ThrowErrno(std::string("Can't open file: ") + path_.get());
+ ThrowErrno(std::string("Can't open file: ") + path_.toString());
}
struct stat sbuf;
if(::fstat(info_->fd_, &info_->sbuf_) < 0) {
::close(info_->fd_);
delete info_;
info_ = 0;
- ThrowErrno(std::string("Can't stat file: ") + path_.get());
+ ThrowErrno(std::string("Can't stat file: ") + path_.toString());
}
} else {
- throw std::string("Can't open file: ") + path_.get();
+ throw std::string("Can't open file: ") + path_.toString();
}
}
@@ -103,7 +103,7 @@ void* MappedFile::map() {
base_ = ::mmap(0, map_size, prot, flags, info_->fd_, 0);
if (base_ == MAP_FAILED)
- ThrowErrno(std::string("Can't map file:") + path_.get());
+ ThrowErrno(std::string("Can't map file:") + path_.toString());
}
return base_;
}
diff --git a/lib/System/Unix/Path.cpp b/lib/System/Unix/Path.cpp
index 5d2a4b6..d3e4d96 100644
--- a/lib/System/Unix/Path.cpp
+++ b/lib/System/Unix/Path.cpp
@@ -21,7 +21,6 @@
#include "Unix.h"
#include <sys/stat.h>
#include <fcntl.h>
-#include <fstream>
#include <utime.h>
#include <dirent.h>
@@ -192,10 +191,13 @@ bool
Path::isBytecodeFile() const {
char buffer[ 4];
buffer[0] = 0;
- std::ifstream f(path.c_str());
- f.read(buffer, 4);
- if (f.bad())
- ThrowErrno("can't read file signature");
+ int fd = ::open(path.c_str(),O_RDONLY);
+ if (fd < 0)
+ return false;
+ ssize_t bytes_read = ::read(fd, buffer, 4);
+ ::close(fd);
+ if (4 != bytes_read)
+ return false;
return (buffer[0] == 'l' && buffer[1] == 'l' && buffer[2] == 'v' &&
(buffer[3] == 'c' || buffer[3] == 'm'));
@@ -522,7 +524,8 @@ bool
Path::renameFile(const Path& newName) {
if (!isFile()) return false;
if (0 != rename(path.c_str(), newName.c_str()))
- ThrowErrno(std::string("can't rename ") + path + " as " + newName.get());
+ ThrowErrno(std::string("can't rename ") + path + " as " +
+ newName.toString());
return true;
}
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
index 5d2a4b6..d3e4d96 100644
--- a/lib/System/Unix/Path.inc
+++ b/lib/System/Unix/Path.inc
@@ -21,7 +21,6 @@
#include "Unix.h"
#include <sys/stat.h>
#include <fcntl.h>
-#include <fstream>
#include <utime.h>
#include <dirent.h>
@@ -192,10 +191,13 @@ bool
Path::isBytecodeFile() const {
char buffer[ 4];
buffer[0] = 0;
- std::ifstream f(path.c_str());
- f.read(buffer, 4);
- if (f.bad())
- ThrowErrno("can't read file signature");
+ int fd = ::open(path.c_str(),O_RDONLY);
+ if (fd < 0)
+ return false;
+ ssize_t bytes_read = ::read(fd, buffer, 4);
+ ::close(fd);
+ if (4 != bytes_read)
+ return false;
return (buffer[0] == 'l' && buffer[1] == 'l' && buffer[2] == 'v' &&
(buffer[3] == 'c' || buffer[3] == 'm'));
@@ -522,7 +524,8 @@ bool
Path::renameFile(const Path& newName) {
if (!isFile()) return false;
if (0 != rename(path.c_str(), newName.c_str()))
- ThrowErrno(std::string("can't rename ") + path + " as " + newName.get());
+ ThrowErrno(std::string("can't rename ") + path + " as " +
+ newName.toString());
return true;
}
diff --git a/lib/System/Unix/Program.cpp b/lib/System/Unix/Program.cpp
index 18fcafe..ae53720 100644
--- a/lib/System/Unix/Program.cpp
+++ b/lib/System/Unix/Program.cpp
@@ -81,7 +81,7 @@ int
Program::ExecuteAndWait(const Path& path,
const std::vector<std::string>& args) {
if (!path.executable())
- throw path.get() + " is not executable";
+ throw path.toString() + " is not executable";
#ifdef HAVE_SYS_WAIT_H
// Create local versions of the parameters that can be passed into execve()
@@ -98,7 +98,8 @@ Program::ExecuteAndWait(const Path& path,
switch (fork()) {
// An error occured: Return to the caller.
case -1:
- ThrowErrno(std::string("Couldn't execute program '") + path.get() + "'");
+ ThrowErrno(std::string("Couldn't execute program '") + path.toString() +
+ "'");
break;
// Child process: Execute the program.
@@ -116,13 +117,15 @@ Program::ExecuteAndWait(const Path& path,
// Parent process: Wait for the child process to terminate.
int status;
if ((::wait (&status)) == -1)
- ThrowErrno(std::string("Failed waiting for program '") + path.get() + "'");
+ ThrowErrno(std::string("Failed waiting for program '") + path.toString()
+ + "'");
// If the program exited normally with a zero exit status, return success!
if (WIFEXITED (status))
return WEXITSTATUS(status);
else if (WIFSIGNALED(status))
- throw std::string("Program '") + path.get() + "' received terminating signal.";
+ throw std::string("Program '") + path.toString() +
+ "' received terminating signal.";
else
return 0;
diff --git a/lib/System/Unix/Program.inc b/lib/System/Unix/Program.inc
index 18fcafe..ae53720 100644
--- a/lib/System/Unix/Program.inc
+++ b/lib/System/Unix/Program.inc
@@ -81,7 +81,7 @@ int
Program::ExecuteAndWait(const Path& path,
const std::vector<std::string>& args) {
if (!path.executable())
- throw path.get() + " is not executable";
+ throw path.toString() + " is not executable";
#ifdef HAVE_SYS_WAIT_H
// Create local versions of the parameters that can be passed into execve()
@@ -98,7 +98,8 @@ Program::ExecuteAndWait(const Path& path,
switch (fork()) {
// An error occured: Return to the caller.
case -1:
- ThrowErrno(std::string("Couldn't execute program '") + path.get() + "'");
+ ThrowErrno(std::string("Couldn't execute program '") + path.toString() +
+ "'");
break;
// Child process: Execute the program.
@@ -116,13 +117,15 @@ Program::ExecuteAndWait(const Path& path,
// Parent process: Wait for the child process to terminate.
int status;
if ((::wait (&status)) == -1)
- ThrowErrno(std::string("Failed waiting for program '") + path.get() + "'");
+ ThrowErrno(std::string("Failed waiting for program '") + path.toString()
+ + "'");
// If the program exited normally with a zero exit status, return success!
if (WIFEXITED (status))
return WEXITSTATUS(status);
else if (WIFSIGNALED(status))
- throw std::string("Program '") + path.get() + "' received terminating signal.";
+ throw std::string("Program '") + path.toString() +
+ "' received terminating signal.";
else
return 0;
diff --git a/lib/System/Unix/Signals.cpp b/lib/System/Unix/Signals.cpp
index 88e8766..8a3eee1 100644
--- a/lib/System/Unix/Signals.cpp
+++ b/lib/System/Unix/Signals.cpp
@@ -138,7 +138,7 @@ void sys::RemoveFileOnSignal(const sys::Path &Filename) {
if (FilesToRemove == 0)
FilesToRemove = new std::vector<std::string>;
- FilesToRemove->push_back(Filename.get());
+ FilesToRemove->push_back(Filename.toString());
std::for_each(IntSigs, IntSigsEnd, RegisterHandler);
std::for_each(KillSigs, KillSigsEnd, RegisterHandler);
diff --git a/lib/System/Unix/Signals.inc b/lib/System/Unix/Signals.inc
index 88e8766..8a3eee1 100644
--- a/lib/System/Unix/Signals.inc
+++ b/lib/System/Unix/Signals.inc
@@ -138,7 +138,7 @@ void sys::RemoveFileOnSignal(const sys::Path &Filename) {
if (FilesToRemove == 0)
FilesToRemove = new std::vector<std::string>;
- FilesToRemove->push_back(Filename.get());
+ FilesToRemove->push_back(Filename.toString());
std::for_each(IntSigs, IntSigsEnd, RegisterHandler);
std::for_each(KillSigs, KillSigsEnd, RegisterHandler);