summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-08-23 00:39:35 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-08-23 00:39:35 +0000
commit8db844241b25c5a350d3edeeac459fca69c7ae51 (patch)
treef207ee659a6aa42169484ebf0fd20b313c5e8b54 /llvm/lib
parent3376c6d8c572d25b87670cd44e00e018a27b37b3 (diff)
downloadbcm5719-llvm-8db844241b25c5a350d3edeeac459fca69c7ae51.tar.gz
bcm5719-llvm-8db844241b25c5a350d3edeeac459fca69c7ae51.zip
For PR797:
Remove exceptions from the Path::create*OnDisk methods. Update their users to handle error messages via arguments and result codes. llvm-svn: 29840
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Bytecode/Archive/ArchiveWriter.cpp6
-rw-r--r--llvm/lib/System/Unix/Path.inc37
2 files changed, 26 insertions, 17 deletions
diff --git a/llvm/lib/Bytecode/Archive/ArchiveWriter.cpp b/llvm/lib/Bytecode/Archive/ArchiveWriter.cpp
index c99d8510c51..c3fda5fe1a9 100644
--- a/llvm/lib/Bytecode/Archive/ArchiveWriter.cpp
+++ b/llvm/lib/Bytecode/Archive/ArchiveWriter.cpp
@@ -389,7 +389,8 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress,
// Create a temporary file to store the archive in
sys::Path TmpArchive = archPath;
- TmpArchive.createTemporaryFileOnDisk();
+ if (TmpArchive.createTemporaryFileOnDisk(error))
+ return false;
// Make sure the temporary gets removed if we crash
sys::RemoveFileOnSignal(TmpArchive);
@@ -452,7 +453,8 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress,
// Open another temporary file in order to avoid invalidating the
// mmapped data
sys::Path FinalFilePath = archPath;
- FinalFilePath.createTemporaryFileOnDisk();
+ if (FinalFilePath.createTemporaryFileOnDisk(error))
+ return false;
sys::RemoveFileOnSignal(FinalFilePath);
std::ofstream FinalFile(FinalFilePath.c_str(), io_mode);
diff --git a/llvm/lib/System/Unix/Path.inc b/llvm/lib/System/Unix/Path.inc
index db7f4c6fabf..7fc77a99766 100644
--- a/llvm/lib/System/Unix/Path.inc
+++ b/llvm/lib/System/Unix/Path.inc
@@ -517,7 +517,7 @@ Path::eraseSuffix() {
}
bool
-Path::createDirectoryOnDisk( bool create_parents) {
+Path::createDirectoryOnDisk( bool create_parents, std::string* ErrMsg ) {
// Get a writeable copy of the path name
char pathname[MAXPATHLEN];
path.copy(pathname,MAXPATHLEN);
@@ -540,8 +540,11 @@ Path::createDirectoryOnDisk( bool create_parents) {
while ( next != 0 ) {
*next = 0;
if (0 != access(pathname, F_OK | R_OK | W_OK))
- if (0 != mkdir(pathname, S_IRWXU | S_IRWXG))
- ThrowErrno(std::string(pathname) + ": can't create directory");
+ if (0 != mkdir(pathname, S_IRWXU | S_IRWXG)) {
+ MakeErrMsg(ErrMsg,
+ std::string(pathname) + ": can't create directory");
+ return true;
+ }
char* save = next;
next = strchr(next+1,'/');
*save = '/';
@@ -549,33 +552,37 @@ Path::createDirectoryOnDisk( bool create_parents) {
}
if (0 != access(pathname, F_OK | R_OK))
- if (0 != mkdir(pathname, S_IRWXU | S_IRWXG))
- ThrowErrno(std::string(pathname) + ": can't create directory");
- return true;
+ if (0 != mkdir(pathname, S_IRWXU | S_IRWXG)) {
+ MakeErrMsg(ErrMsg, std::string(pathname) + ": can't create directory");
+ return true;
+ }
+ return false;
}
bool
-Path::createFileOnDisk() {
+Path::createFileOnDisk(std::string* ErrMsg) {
// Create the file
int fd = ::creat(path.c_str(), S_IRUSR | S_IWUSR);
- if (fd < 0)
- ThrowErrno(path + ": can't create file");
+ if (fd < 0) {
+ MakeErrMsg(ErrMsg, path + ": can't create file");
+ return true;
+ }
::close(fd);
-
- return true;
+ return false;
}
bool
-Path::createTemporaryFileOnDisk(bool reuse_current) {
+Path::createTemporaryFileOnDisk(bool reuse_current, std::string* ErrMsg) {
// Make this into a unique file name
makeUnique( reuse_current );
// create the file
- int outFile = ::open(path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666);
- if (outFile != -1) {
- ::close(outFile);
+ int fd = ::open(path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666);
+ if (fd < 0) {
+ MakeErrMsg(ErrMsg, path + ": can't create temporary file");
return true;
}
+ ::close(fd);
return false;
}
OpenPOWER on IntegriCloud