summaryrefslogtreecommitdiff
path: root/include/llvm/Support/FileSystem.h
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-07-05 21:01:08 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-07-05 21:01:08 +0000
commit200c748a8643cd127271f4d6849da1e147d4442f (patch)
tree0eacbac147a7d5d59d0e41281c4b11f4784b0c50 /include/llvm/Support/FileSystem.h
parentcd56727b555fd009c691d1c4ae308fbaf50e0c4f (diff)
downloadllvm-200c748a8643cd127271f4d6849da1e147d4442f.tar.gz
llvm-200c748a8643cd127271f4d6849da1e147d4442f.tar.bz2
llvm-200c748a8643cd127271f4d6849da1e147d4442f.tar.xz
Add a createUniqueFile function and switch llvm's users of unique_file.
This function is complementary to createTemporaryFile. It handles the case were the unique file is *not* temporary: we will rename it in the end. Since we will rename it, the file has to be in the same filesystem as the final destination and we don't prepend the system temporary directory. This has a small semantic difference from unique_file: the default mode is 0666. This matches the behavior of most unix tools. For example, with this change lld now produces files with the same permissions as ld. I will add a test of this change when I port clang over to createUniqueFile (next commit). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185726 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/FileSystem.h')
-rw-r--r--include/llvm/Support/FileSystem.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/include/llvm/Support/FileSystem.h b/include/llvm/Support/FileSystem.h
index d8f79ba69d..b729a992c3 100644
--- a/include/llvm/Support/FileSystem.h
+++ b/include/llvm/Support/FileSystem.h
@@ -575,6 +575,35 @@ error_code unique_file(const Twine &model, int &result_fd,
error_code unique_file(const Twine &Model, SmallVectorImpl<char> &ResultPath,
bool MakeAbsolute = true);
+/// @brief Create a uniquely named file.
+///
+/// Generates a unique path suitable for a temporary file and then opens it as a
+/// file. The name is based on \a model with '%' replaced by a random char in
+/// [0-9a-f]. If \a model is not an absolute path, a suitable temporary
+/// directory will be prepended.
+///
+/// Example: clang-%%-%%-%%-%%-%%.s => clang-a0-b1-c2-d3-e4.s
+///
+/// This is an atomic operation. Either the file is created and opened, or the
+/// file system is left untouched.
+///
+/// The intendend use is for files that are to be kept, possibly after
+/// renaming them. For example, when running 'clang -c foo.o', the file can
+/// be first created as foo-abc123.o and then renamed.
+///
+/// @param Model Name to base unique path off of.
+/// @param ResultFD Set to the opened file's file descriptor.
+/// @param ResultPath Set to the opened file's absolute path.
+/// @returns errc::success if Result{FD,Path} have been successfully set,
+/// otherwise a platform specific error_code.
+error_code createUniqueFile(const Twine &Model, int &ResultFD,
+ SmallVectorImpl<char> &ResultPath,
+ unsigned Mode = all_read | all_write);
+
+/// @brief Simpler version for clients that don't want an open file.
+error_code createUniqueFile(const Twine &Model,
+ SmallVectorImpl<char> &ResultPath);
+
/// @brief Create a file in the system temporary directory.
///
/// The filename is of the form prefix-random_chars.suffix. Since the directory