OSDN Git Service

opening "-" automatically yields stdout.
authorChris Lattner <sabre@nondot.org>
Sun, 17 Aug 2008 03:53:23 +0000 (03:53 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 17 Aug 2008 03:53:23 +0000 (03:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54863 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/raw_ostream.cpp

index e47bccd..a4dc797 100644 (file)
@@ -34,6 +34,13 @@ void raw_ostream::handle() {}
 /// information about the error is put into ErrorInfo, and the stream should
 /// be immediately destroyed.
 raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo) {
+  // Handle "-" as stdout.
+  if (Filename[0] == '-' && Filename[1] == 0) {
+    FD = STDOUT_FILENO;
+    ShouldClose = false;
+    return;
+  }
+  
   FD = open(Filename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
   if (FD < 0) {
     ErrorInfo = "Error opening output file '" + std::string(Filename) + "'";