[llvm] r184206 - Add a version of unique_file that return just the file name.

Rafael Espindola rafael.espindola at gmail.com
Tue Jun 18 10:01:00 PDT 2013


Author: rafael
Date: Tue Jun 18 12:01:00 2013
New Revision: 184206

URL: http://llvm.org/viewvc/llvm-project?rev=184206&view=rev
Log:
Add a version of unique_file that return just the file name.

Modified:
    llvm/trunk/include/llvm/Support/FileSystem.h
    llvm/trunk/lib/Support/PathV2.cpp
    llvm/trunk/tools/bugpoint/ExecutionDriver.cpp
    llvm/trunk/tools/bugpoint/OptimizerDriver.cpp

Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=184206&r1=184205&r2=184206&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Tue Jun 18 12:01:00 2013
@@ -509,6 +509,10 @@ error_code unique_file(const Twine &mode
                        SmallVectorImpl<char> &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<char> &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

Modified: llvm/trunk/lib/Support/PathV2.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PathV2.cpp?rev=184206&r1=184205&r2=184206&view=diff
==============================================================================
--- llvm/trunk/lib/Support/PathV2.cpp (original)
+++ llvm/trunk/lib/Support/PathV2.cpp Tue Jun 18 12:01:00 2013
@@ -18,8 +18,11 @@
 #include <cctype>
 #include <cstdio>
 #include <cstring>
-#ifdef __APPLE__
+
+#if !defined(_MSC_VER) && !defined(__MINGW32__)
 #include <unistd.h>
+#else
+#include <io.h>
 #endif
 
 namespace {
@@ -622,6 +625,14 @@ bool is_relative(const Twine &path) {
 
 namespace fs {
 
+error_code unique_file(const Twine &Model, SmallVectorImpl<char> &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<char> &path) {
   StringRef p(path.data(), path.size());
 

Modified: llvm/trunk/tools/bugpoint/ExecutionDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ExecutionDriver.cpp?rev=184206&r1=184205&r2=184206&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/ExecutionDriver.cpp (original)
+++ llvm/trunk/tools/bugpoint/ExecutionDriver.cpp Tue Jun 18 12:01:00 2013
@@ -21,12 +21,6 @@
 #include "llvm/Support/raw_ostream.h"
 #include <fstream>
 
-#if !defined(_MSC_VER) && !defined(__MINGW32__)
-#include <unistd.h>
-#else
-#include <io.h>
-#endif
-
 using namespace llvm;
 
 namespace {
@@ -338,15 +332,13 @@ std::string BugDriver::executeProgram(co
 
   // 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<std::string> SharedObjs(AdditionalSOs);

Modified: llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/OptimizerDriver.cpp?rev=184206&r1=184205&r2=184206&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/OptimizerDriver.cpp (original)
+++ llvm/trunk/tools/bugpoint/OptimizerDriver.cpp Tue Jun 18 12:01:00 2013
@@ -34,12 +34,6 @@
 
 #include <fstream>
 
-#if !defined(_MSC_VER) && !defined(__MINGW32__)
-#include <unistd.h>
-#else
-#include <io.h>
-#endif
-
 using namespace llvm;
 
 namespace llvm {
@@ -130,16 +124,14 @@ bool BugDriver::runPasses(Module *Progra
   // 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;





More information about the llvm-commits mailing list