Convert tools to use tool_output_file, and introduce error
[oota-llvm.git] / tools / opt / GraphPrinters.cpp
index 6a9e96516db5c8adfdadbe8a61c05a88f69a0e8f..d689a4a1dae2e41eec13eb312b4eda8a252630ce 100644 (file)
@@ -28,13 +28,19 @@ static void WriteGraphToFile(raw_ostream &O, const std::string &GraphName,
   std::string Filename = GraphName + ".dot";
   O << "Writing '" << Filename << "'...";
   std::string ErrInfo;
-  raw_fd_ostream F(Filename.c_str(), ErrInfo);
+  tool_output_file F(Filename.c_str(), ErrInfo);
 
-  if (ErrInfo.empty())
+  if (ErrInfo.empty()) {
     WriteGraph(F, GT);
-  else
-    O << "  error opening file for writing!";
-  O << "\n";
+    F.close();
+    if (!F.has_error()) {
+      O << "\n";
+      F.keep();
+      return;
+    }
+  }
+  F.clear_error();
+  O << "  error opening file for writing!\n";
 }