LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ToolOutputFile.cpp
Go to the documentation of this file.
1 //===--- ToolOutputFile.cpp - Implement the tool_output_file class --------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This implements the tool_output_file class.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 #include "llvm/Support/Signals.h"
17 using namespace llvm;
18 
19 tool_output_file::CleanupInstaller::CleanupInstaller(const char *filename)
20  : Filename(filename), Keep(false) {
21  // Arrange for the file to be deleted if the process is killed.
22  if (Filename != "-")
23  sys::RemoveFileOnSignal(Filename);
24 }
25 
26 tool_output_file::CleanupInstaller::~CleanupInstaller() {
27  // Delete the file if the client hasn't told us not to.
28  if (!Keep && Filename != "-") {
29  bool Existed;
30  sys::fs::remove(Filename, Existed);
31  }
32 
33  // Ok, the file is successfully written and closed, or deleted. There's no
34  // further need to clean it up on signals.
35  if (Filename != "-")
37 }
38 
39 tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo,
41  : Installer(filename), OS(filename, ErrorInfo, Flags) {
42  // If open fails, no cleanup is needed.
43  if (!ErrorInfo.empty())
44  Installer.Keep = true;
45 }
46 
47 tool_output_file::tool_output_file(const char *Filename, int FD)
48  : Installer(Filename), OS(FD, true) {
49 }
#define false
Definition: ConvertUTF.c:64
#define true
Definition: ConvertUTF.c:65
void DontRemoveFileOnSignal(StringRef Filename)
bool RemoveFileOnSignal(StringRef Filename, std::string *ErrMsg=0)
Remove a file if a fatal signal occurs.
error_code remove(const Twine &path, bool &existed)
Remove path. Equivalent to POSIX remove().
const StringRef filename(StringRef path)
Get filename.
Definition: Path.cpp:467
tool_output_file(const char *filename, std::string &ErrorInfo, sys::fs::OpenFlags Flags=sys::fs::F_None)