Added raw_fd_ostream::close().
authorTed Kremenek <kremenek@apple.com>
Thu, 23 Oct 2008 23:49:09 +0000 (23:49 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 23 Oct 2008 23:49:09 +0000 (23:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58052 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/raw_ostream.h
lib/Support/raw_ostream.cpp

index af53477cea31af95173c94b270059381f59a4f99..9b307dbf956d8a203da334c86905d6c1a6a13a52 100644 (file)
@@ -168,6 +168,9 @@ public:
   /// subclasses.  This outputs the currently buffered data and resets the
   /// buffer to empty.
   virtual void flush_impl();
+  
+  /// close - Manually flush the stream and close the file.
+  void close();  
 };
   
 /// raw_stdout_ostream - This is a stream that always prints to stdout.
index f3a53a5061751c1df353ed5d2371e367703ae0ca..a4c293660b0b37889357e194e05d6456451ddd30 100644 (file)
@@ -220,17 +220,28 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo) {
 }
 
 raw_fd_ostream::~raw_fd_ostream() {
-  flush();
-  if (ShouldClose)
-    close(FD);
+  if (FD >= 0) {
+    flush();
+    if (ShouldClose)
+      ::close(FD);
+  }
 }
 
 void raw_fd_ostream::flush_impl() {
+  assert (FD >= 0 && "File already closed.");
   if (OutBufCur-OutBufStart)
     ::write(FD, OutBufStart, OutBufCur-OutBufStart);
   HandleFlush();
 }
 
+void raw_fd_ostream::close() {
+  assert (ShouldClose);
+  ShouldClose = false;
+  flush();
+  ::close(FD);
+  FD = -1;
+}
+
 //===----------------------------------------------------------------------===//
 //  raw_stdout/err_ostream
 //===----------------------------------------------------------------------===//