summaryrefslogtreecommitdiffstats
path: root/llvm/lib/System/Unix
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-08-22 19:01:30 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-08-22 19:01:30 +0000
commit6ba87bbfd303182536cf3564bbae838eb998cd85 (patch)
tree42143dda2d42ea66b9d1002d25d185dfb9e624b2 /llvm/lib/System/Unix
parent2e9f1bc056f3a4467e4c59a1631aa1e0c73b7ddf (diff)
downloadbcm5719-llvm-6ba87bbfd303182536cf3564bbae838eb998cd85.tar.gz
bcm5719-llvm-6ba87bbfd303182536cf3564bbae838eb998cd85.zip
Make the sys::Path::GetTemporaryDirectory method not throw exceptions and
adjust users of it to compensate. llvm-svn: 29831
Diffstat (limited to 'llvm/lib/System/Unix')
-rw-r--r--llvm/lib/System/Unix/Path.inc53
1 files changed, 30 insertions, 23 deletions
diff --git a/llvm/lib/System/Unix/Path.inc b/llvm/lib/System/Unix/Path.inc
index bd29d8da8d1..b1e51b0aff9 100644
--- a/llvm/lib/System/Unix/Path.inc
+++ b/llvm/lib/System/Unix/Path.inc
@@ -63,16 +63,6 @@ inline bool lastIsSlash(const std::string& path) {
namespace llvm {
using namespace sys;
-Path::Path(const std::string& unverified_path) : path(unverified_path) {
- if (unverified_path.empty())
- return;
- if (this->isValid())
- return;
- // oops, not valid.
- path.clear();
- ThrowErrno(unverified_path + ": path is not valid");
-}
-
bool
Path::isValid() const {
// Check some obvious things
@@ -97,14 +87,17 @@ Path::GetRootDirectory() {
}
Path
-Path::GetTemporaryDirectory() {
+Path::GetTemporaryDirectory(std::string* ErrMsg ) {
#if defined(HAVE_MKDTEMP)
// The best way is with mkdtemp but that's not available on many systems,
// Linux and FreeBSD have it. Others probably won't.
char pathname[MAXPATHLEN];
strcpy(pathname,"/tmp/llvm_XXXXXX");
- if (0 == mkdtemp(pathname))
- ThrowErrno(std::string(pathname) + ": can't create temporary directory");
+ if (0 == mkdtemp(pathname)) {
+ MakeErrMsg(ErrMsg,
+ std::string(pathname) + ": can't create temporary directory");
+ return Path();
+ }
Path result;
result.set(pathname);
assert(result.isValid() && "mkdtemp didn't create a valid pathname!");
@@ -118,12 +111,18 @@ Path::GetTemporaryDirectory() {
char pathname[MAXPATHLEN];
strcpy(pathname, "/tmp/llvm_XXXXXX");
int fd = 0;
- if (-1 == (fd = mkstemp(pathname)))
- ThrowErrno(std::string(pathname) + ": can't create temporary directory");
+ if (-1 == (fd = mkstemp(pathname))) {
+ MakeErrMsg(ErrMsg,
+ std::string(pathname) + ": can't create temporary directory");
+ return Path();
+ }
::close(fd);
::unlink(pathname); // start race condition, ignore errors
- if (-1 == ::mkdir(pathname, S_IRWXU)) // end race condition
- ThrowErrno(std::string(pathname) + ": can't create temporary directory");
+ if (-1 == ::mkdir(pathname, S_IRWXU)) { // end race condition
+ MakeErrMsg(ErrMsg,
+ std::string(pathname) + ": can't create temporary directory");
+ return Path();
+ }
Path result;
result.set(pathname);
assert(result.isValid() && "mkstemp didn't create a valid pathname!");
@@ -137,10 +136,16 @@ Path::GetTemporaryDirectory() {
char pathname[MAXPATHLEN];
strcpy(pathname, "/tmp/llvm_XXXXXX");
char *TmpName = ::mktemp(pathname);
- if (TmpName == 0)
- ThrowErrno(std::string(TmpName) + ": can't create unique directory name");
- if (-1 == ::mkdir(TmpName, S_IRWXU))
- ThrowErrno(std::string(TmpName) + ": can't create temporary directory");
+ if (TmpName == 0) {
+ MakeErrMsg(ErrMsg,
+ std::string(TmpName) + ": can't create unique directory name");
+ return Path();
+ }
+ if (-1 == ::mkdir(TmpName, S_IRWXU)) {
+ MakeErrMsg(ErrMsg,
+ std::string(TmpName) + ": can't create temporary directory");
+ return Path();
+ }
Path result;
result.set(TmpName);
assert(result.isValid() && "mktemp didn't create a valid pathname!");
@@ -160,8 +165,10 @@ Path::GetTemporaryDirectory() {
num++;
sprintf(pathname, "/tmp/llvm_%010u", unsigned(num));
} while ( 0 == access(pathname, F_OK ) );
- if (-1 == ::mkdir(pathname, S_IRWXU))
- ThrowErrno(std::string(pathname) + ": can't create temporary directory");
+ if (-1 == ::mkdir(pathname, S_IRWXU)) {
+ MakeErrMsg(ErrMsg,
+ std::string(pathname) + ": can't create temporary directory");
+ return Path();
Path result;
result.set(pathname);
assert(result.isValid() && "mkstemp didn't create a valid pathname!");
OpenPOWER on IntegriCloud