Added raw_fd_ostream::close().

llvm-svn: 58052
This commit is contained in:
Ted Kremenek 2008-10-23 23:49:09 +00:00
parent 45e2b90d3d
commit 3c6de496b0
2 changed files with 17 additions and 3 deletions

View 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.

View 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
//===----------------------------------------------------------------------===//