1 //===--- ToolOutputFile.cpp - Implement the ToolOutputFile class --------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This implements the ToolOutputFile class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/ToolOutputFile.h"
15 #include "llvm/Support/FileSystem.h"
16 #include "llvm/Support/Signals.h"
19 ToolOutputFile::CleanupInstaller::CleanupInstaller(StringRef Filename
)
20 : Filename(Filename
), Keep(false) {
21 // Arrange for the file to be deleted if the process is killed.
23 sys::RemoveFileOnSignal(Filename
);
26 ToolOutputFile::CleanupInstaller::~CleanupInstaller() {
27 // Delete the file if the client hasn't told us not to.
28 if (!Keep
&& Filename
!= "-")
29 sys::fs::remove(Filename
);
31 // Ok, the file is successfully written and closed, or deleted. There's no
32 // further need to clean it up on signals.
34 sys::DontRemoveFileOnSignal(Filename
);
37 ToolOutputFile::ToolOutputFile(StringRef Filename
, std::error_code
&EC
,
38 sys::fs::OpenFlags Flags
)
39 : Installer(Filename
), OS(Filename
, EC
, Flags
) {
40 // If open fails, no cleanup is needed.
42 Installer
.Keep
= true;
45 ToolOutputFile::ToolOutputFile(StringRef Filename
, int FD
)
46 : Installer(Filename
), OS(FD
, true) {}