Make DebugLoc independent of DwarfWriter.
[oota-llvm.git] / lib / System / Unix / Program.inc
index 6ff69ca133e443878d683e9aea3f2178626ec8c2..cdc6fee609491c28f938fcb34f1199229d6815f7 100644 (file)
@@ -99,7 +99,7 @@ static bool RedirectIO(const Path *Path, int FD, std::string* ErrMsg) {
   int InFD = open(File.c_str(), FD == 0 ? O_RDONLY : O_WRONLY|O_CREAT, 0666);
   if (InFD == -1) {
     MakeErrMsg(ErrMsg, "Cannot open file '" + File + "' for "
-              + (FD == 0 ? "input" : "output") + "!\n");
+              + (FD == 0 ? "input" : "output"));
     return true;
   }
 
@@ -170,14 +170,21 @@ Program::ExecuteAndWait(const Path& path,
     case 0: {
       // Redirect file descriptors...
       if (redirects) {
+        // Redirect stdin
         if (RedirectIO(redirects[0], 0, ErrMsg)) { return -1; }
+        // Redirect stdout
         if (RedirectIO(redirects[1], 1, ErrMsg)) { return -1; }
         if (redirects[1] && redirects[2] && 
-            *(redirects[1]) != *(redirects[2])) {
+            *(redirects[1]) == *(redirects[2])) {
+          // If stdout and stderr should go to the same place, redirect stderr
+          // to the FD already open for stdout.
+          if (-1 == dup2(1,2)) {
+            MakeErrMsg(ErrMsg, "Can't redirect stderr to stdout");
+            return -1;
+          }
+        } else {
+          // Just redirect stderr
           if (RedirectIO(redirects[2], 2, ErrMsg)) { return -1; }
-        } else if (-1 == dup2(1,2)) {
-          MakeErrMsg(ErrMsg, "Can't redirect");
-          return -1;
         }
       }