For PR797:
Remove exceptions from the Path::create*OnDisk methods. Update their users
to handle error messages via arguments and result codes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29840 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp
index d2d8c85..e5abea4 100644
--- a/tools/llvm-ar/llvm-ar.cpp
+++ b/tools/llvm-ar/llvm-ar.cpp
@@ -425,8 +425,8 @@
 }
 
 // doExtract - Implement the 'x' operation. This function extracts files back to
-// the file system, making sure to uncompress any that were compressed.
-void doExtract() {
+// the file system, making sure to uncompress any that were compressed
+bool doExtract(std::string* ErrMsg) {
   buildPaths(false);
   unsigned countDown = Count;
   for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end();
@@ -438,7 +438,8 @@
       if (I->hasPath()) {
         sys::Path dirs(I->getPath());
         dirs.eraseComponent();
-        dirs.createDirectoryOnDisk(/*create_parents=*/true);
+        if (dirs.createDirectoryOnDisk(/*create_parents=*/true, ErrMsg)) 
+          return true;
       }
 
       // Open up a file stream for writing
@@ -464,6 +465,7 @@
         I->getPath().setStatusInfoOnDisk(I->getFileStatus());
     }
   }
+  return false;
 }
 
 // doDelete - Implement the delete operation. This function deletes zero or more
@@ -711,6 +713,7 @@
     std::auto_ptr<Archive> AutoArchive(TheArchive);
 
     // Perform the operation
+    std::string ErrMsg;
     switch (Operation) {
       case Print:           doPrint(); break;
       case Delete:          doDelete(); break;
@@ -718,7 +721,12 @@
       case QuickAppend:      /* FALL THROUGH */
       case ReplaceOrInsert: doReplaceOrInsert(); break;
       case DisplayTable:    doDisplayTable(); break;
-      case Extract:         doExtract(); break;
+      case Extract:         
+        if (doExtract(&ErrMsg)) {
+          std::cerr << argv[0] << ": " << ErrMsg << "\n";
+          return 1;
+        }
+        break;
       case NoOperation:
         std::cerr << argv[0] << ": No operation was selected.\n";
         break;
diff --git a/tools/llvm-ld/llvm-ld.cpp b/tools/llvm-ld/llvm-ld.cpp
index 679522f..53f04e6 100644
--- a/tools/llvm-ld/llvm-ld.cpp
+++ b/tools/llvm-ld/llvm-ld.cpp
@@ -492,16 +492,15 @@
           }
           // Get the program arguments
           sys::Path tmp_output("opt_result");
-          if (!tmp_output.createTemporaryFileOnDisk()) {
-            return PrintAndReturn(
-              "Can't create temporary file for post-link optimization");
+          std::string ErrMsg;
+          if (tmp_output.createTemporaryFileOnDisk(&ErrMsg)) {
+            return PrintAndReturn(ErrMsg);
           }
           const char* args[4];
           args[0] = I->c_str();
           args[1] = RealBytecodeOutput.c_str();
           args[2] = tmp_output.c_str();
           args[3] = 0;
-          std::string ErrMsg;
           if (0 == sys::Program::ExecuteAndWait(prog, args, 0,0,0, &ErrMsg)) {
             if (tmp_output.isBytecodeFile()) {
               sys::Path target(RealBytecodeOutput);
diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp
index 570558a..372e6ea 100644
--- a/tools/lto/lto.cpp
+++ b/tools/lto/lto.cpp
@@ -295,7 +295,11 @@
   }
 
   sys::Path tmpAsmFilePath("/tmp/");
-  tmpAsmFilePath.createTemporaryFileOnDisk();
+  std::string ErrMsg;
+  if (tmpAsmFilePath.createTemporaryFileOnDisk(&ErrMsg)) {
+    std::cerr << "lto: " << ErrMsg << "\n";
+    return;
+  }
   sys::RemoveFileOnSignal(tmpAsmFilePath);
 
   std::ofstream asmFile(tmpAsmFilePath.c_str(), io_mode);