Convert tools to use tool_output_file, and introduce error
checking to places which previously lacked it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111651 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/opt/GraphPrinters.cpp b/tools/opt/GraphPrinters.cpp
index 6a9e965..d689a4a 100644
--- a/tools/opt/GraphPrinters.cpp
+++ b/tools/opt/GraphPrinters.cpp
@@ -28,13 +28,19 @@
   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";
 }