diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2006-08-22 19:01:30 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2006-08-22 19:01:30 +0000 |
commit | 487447626c273962744820a370d93ddef961c3f2 (patch) | |
tree | 5452a7c4f1d9d37faf155d7e486719795ae96023 /lib/System | |
parent | be4f88a8b8bb3311e0dc4cde8533763d7923c3ea (diff) | |
download | external_llvm-487447626c273962744820a370d93ddef961c3f2.zip external_llvm-487447626c273962744820a370d93ddef961c3f2.tar.gz external_llvm-487447626c273962744820a370d93ddef961c3f2.tar.bz2 |
Make the sys::Path::GetTemporaryDirectory method not throw exceptions and
adjust users of it to compensate.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29831 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System')
-rw-r--r-- | lib/System/Unix/Path.inc | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc index bd29d8d..b1e51b0 100644 --- a/lib/System/Unix/Path.inc +++ b/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!"); |