summaryrefslogtreecommitdiff
path: root/lib/Support/raw_ostream.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-09-01 14:20:41 +0000
committerDan Gohman <gohman@apple.com>2010-09-01 14:20:41 +0000
commitd4c454317a38d65957edebe62bfc69fc8d9885e8 (patch)
treedbf117519d428f04854447edee010962e68e5753 /lib/Support/raw_ostream.cpp
parent41154114f64c1531764236e9268d2a5ac52e3e91 (diff)
downloadllvm-d4c454317a38d65957edebe62bfc69fc8d9885e8.tar.gz
llvm-d4c454317a38d65957edebe62bfc69fc8d9885e8.tar.bz2
llvm-d4c454317a38d65957edebe62bfc69fc8d9885e8.tar.xz
Make tool_output_file's raw_ostream instance a member variable instead
of a base class. This makes it possible to unregister the file from FilesToRemove when the file is done. Also, this eliminates the need for formatted_tool_output_file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112706 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/raw_ostream.cpp')
-rw-r--r--lib/Support/raw_ostream.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index 371dc8b255..dba46df362 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -670,25 +670,29 @@ uint64_t raw_null_ostream::current_pos() const {
// tool_output_file
//===----------------------------------------------------------------------===//
-/// SetupRemoveOnSignal - This is a helper for tool_output_file's constructor
-/// to allow the signal handlers to be installed before constructing the
-/// base class raw_fd_ostream.
-static const char *SetupRemoveOnSignal(const char *Filename) {
+tool_output_file::CleanupInstaller::CleanupInstaller(const char *filename)
+ : Filename(filename), Keep(false) {
// Arrange for the file to be deleted if the process is killed.
- if (strcmp(Filename, "-") != 0)
+ if (Filename != "-")
sys::RemoveFileOnSignal(sys::Path(Filename));
- return Filename;
}
-tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo,
- unsigned Flags)
- : raw_fd_ostream(SetupRemoveOnSignal(filename), ErrorInfo, Flags),
- Filename(filename),
- Keep(!ErrorInfo.empty() /* If open fails, no cleanup is needed. */) {
-}
-
-tool_output_file::~tool_output_file() {
+tool_output_file::CleanupInstaller::~CleanupInstaller() {
// Delete the file if the client hasn't told us not to.
if (!Keep && Filename != "-")
sys::Path(Filename).eraseFromDisk();
+
+ // Ok, the file is successfully written and closed, or deleted. There's no
+ // further need to clean it up on signals.
+ if (Filename != "-")
+ sys::DontRemoveFileOnSignal(sys::Path(Filename));
+}
+
+tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo,
+ unsigned Flags)
+ : Installer(filename),
+ OS(filename, ErrorInfo, Flags) {
+ // If open fails, no cleanup is needed.
+ if (!ErrorInfo.empty())
+ Installer.Keep = true;
}