[llvm-commits] [llvm] r58052 - in /llvm/trunk: include/llvm/Support/raw_ostream.h lib/Support/raw_ostream.cpp

Ted Kremenek kremenek at apple.com
Thu Oct 23 16:49:10 PDT 2008


Author: kremenek
Date: Thu Oct 23 18:49:09 2008
New Revision: 58052

URL: http://llvm.org/viewvc/llvm-project?rev=58052&view=rev
Log:
Added raw_fd_ostream::close().

Modified:
    llvm/trunk/include/llvm/Support/raw_ostream.h
    llvm/trunk/lib/Support/raw_ostream.cpp

Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=58052&r1=58051&r2=58052&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
+++ llvm/trunk/include/llvm/Support/raw_ostream.h Thu Oct 23 18:49:09 2008
@@ -168,6 +168,9 @@
   /// 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.

Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=58052&r1=58051&r2=58052&view=diff

==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Thu Oct 23 18:49:09 2008
@@ -220,17 +220,28 @@
 }
 
 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
 //===----------------------------------------------------------------------===//





More information about the llvm-commits mailing list