From 8ee23f00c7e9343d09313051c318906558d6ad17 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 18 Jun 2013 17:01:00 +0000 Subject: [PATCH] Add a version of unique_file that return just the file name. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184206 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/FileSystem.h | 4 ++++ lib/Support/PathV2.cpp | 13 ++++++++++++- tools/bugpoint/ExecutionDriver.cpp | 10 +--------- tools/bugpoint/OptimizerDriver.cpp | 12 ++---------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/include/llvm/Support/FileSystem.h b/include/llvm/Support/FileSystem.h index 79f85539c03..11c78cc9394 100644 --- a/include/llvm/Support/FileSystem.h +++ b/include/llvm/Support/FileSystem.h @@ -509,6 +509,10 @@ error_code unique_file(const Twine &model, int &result_fd, SmallVectorImpl &result_path, bool makeAbsolute = true, unsigned mode = 0600); +/// @brief Simpler version for clients that don't want an open file. +error_code unique_file(const Twine &Model, SmallVectorImpl &ResultPath, + bool MakeAbsolute = true, unsigned Mode = 0600); + /// @brief Canonicalize path. /// /// Sets result to the file system's idea of what path is. The result is always diff --git a/lib/Support/PathV2.cpp b/lib/Support/PathV2.cpp index 05366202559..0e02953c549 100644 --- a/lib/Support/PathV2.cpp +++ b/lib/Support/PathV2.cpp @@ -18,8 +18,11 @@ #include #include #include -#ifdef __APPLE__ + +#if !defined(_MSC_VER) && !defined(__MINGW32__) #include +#else +#include #endif namespace { @@ -622,6 +625,14 @@ bool is_relative(const Twine &path) { namespace fs { +error_code unique_file(const Twine &Model, SmallVectorImpl &ResultPath, + bool MakeAbsolute, unsigned Mode) { + int FD; + error_code Ret = unique_file(Model, FD, ResultPath, MakeAbsolute, Mode); + close(FD); + return Ret; +} + error_code make_absolute(SmallVectorImpl &path) { StringRef p(path.data(), path.size()); diff --git a/tools/bugpoint/ExecutionDriver.cpp b/tools/bugpoint/ExecutionDriver.cpp index 53908081287..6edf2335f6c 100644 --- a/tools/bugpoint/ExecutionDriver.cpp +++ b/tools/bugpoint/ExecutionDriver.cpp @@ -21,12 +21,6 @@ #include "llvm/Support/raw_ostream.h" #include -#if !defined(_MSC_VER) && !defined(__MINGW32__) -#include -#else -#include -#endif - using namespace llvm; namespace { @@ -338,15 +332,13 @@ std::string BugDriver::executeProgram(const Module *Program, // Check to see if this is a valid output filename... SmallString<128> UniqueFile; - int UniqueFD; - error_code EC = sys::fs::unique_file(OutputFile, UniqueFD, UniqueFile); + error_code EC = sys::fs::unique_file(OutputFile, UniqueFile); if (EC) { errs() << ToolName << ": Error making unique filename: " << EC.message() << "\n"; exit(1); } OutputFile = UniqueFile.str(); - close(UniqueFD); // Figure out which shared objects to run, if any. std::vector SharedObjs(AdditionalSOs); diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp index 3af551f43dd..43f2d3318ae 100644 --- a/tools/bugpoint/OptimizerDriver.cpp +++ b/tools/bugpoint/OptimizerDriver.cpp @@ -34,12 +34,6 @@ #include -#if !defined(_MSC_VER) && !defined(__MINGW32__) -#include -#else -#include -#endif - using namespace llvm; namespace llvm { @@ -130,16 +124,14 @@ bool BugDriver::runPasses(Module *Program, // setup the output file name outs().flush(); SmallString<128> UniqueFilename; - int UniqueFD; - error_code EC = sys::fs::unique_file(OutputPrefix + "-output-%%%%%%%.bc", - UniqueFD, UniqueFilename); + error_code EC = + sys::fs::unique_file(OutputPrefix + "-output-%%%%%%%.bc", UniqueFilename); if (EC) { errs() << getToolName() << ": Error making unique filename: " << EC.message() << "\n"; return 1; } OutputFilename = UniqueFilename.str(); - close(UniqueFD); // We only want the filename. // set up the input file name SmallString<128> InputFilename;