LLVM API Documentation

ToolOutputFile.cpp
Go to the documentation of this file.
00001 //===--- ToolOutputFile.cpp - Implement the tool_output_file class --------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This implements the tool_output_file class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Support/ToolOutputFile.h"
00015 #include "llvm/Support/FileSystem.h"
00016 #include "llvm/Support/Signals.h"
00017 using namespace llvm;
00018 
00019 tool_output_file::CleanupInstaller::CleanupInstaller(StringRef Filename)
00020     : Filename(Filename), Keep(false) {
00021   // Arrange for the file to be deleted if the process is killed.
00022   if (Filename != "-")
00023     sys::RemoveFileOnSignal(Filename);
00024 }
00025 
00026 tool_output_file::CleanupInstaller::~CleanupInstaller() {
00027   // Delete the file if the client hasn't told us not to.
00028   if (!Keep && Filename != "-")
00029     sys::fs::remove(Filename);
00030 
00031   // Ok, the file is successfully written and closed, or deleted. There's no
00032   // further need to clean it up on signals.
00033   if (Filename != "-")
00034     sys::DontRemoveFileOnSignal(Filename);
00035 }
00036 
00037 tool_output_file::tool_output_file(StringRef Filename, std::error_code &EC,
00038                                    sys::fs::OpenFlags Flags)
00039     : Installer(Filename), OS(Filename, EC, Flags) {
00040   // If open fails, no cleanup is needed.
00041   if (EC)
00042     Installer.Keep = true;
00043 }
00044 
00045 tool_output_file::tool_output_file(StringRef Filename, int FD)
00046     : Installer(Filename), OS(FD, true) {}