summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Path.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-07-05 19:56:49 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-07-05 19:56:49 +0000
commit325fa0fd93952946848f1ea33cf3dc8a6de6774a (patch)
treec89a00b228802086ee03f3c54b501a6dca100ae7 /llvm/lib/Support/Path.cpp
parent5603df45df0c7fb2c2fd7771c080e04bd98f6eca (diff)
downloadbcm5719-llvm-325fa0fd93952946848f1ea33cf3dc8a6de6774a.tar.gz
bcm5719-llvm-325fa0fd93952946848f1ea33cf3dc8a6de6774a.zip
Add a higher level createTemporaryFile function.
This function is inspired by clang's Driver::GetTemporaryPath. It hides the pattern used for uniquing and requires simple file names that are always placed in the system temporary directory. llvm-svn: 185716
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r--llvm/lib/Support/Path.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index 5c28c55f267..36fb9f3a4bf 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -654,6 +654,40 @@ error_code unique_file(const Twine &Model, SmallVectorImpl<char> &ResultPath,
return createUniqueEntity(Model, Dummy, ResultPath, MakeAbsolute, 0, FS_Name);
}
+static error_code createTemporaryFile(const Twine &Model, int &ResultFD,
+ llvm::SmallVectorImpl<char> &ResultPath,
+ FSEntity Type) {
+ SmallString<128> Storage;
+ StringRef P = Model.toNullTerminatedStringRef(Storage);
+ assert(P.find_first_of(separators) == StringRef::npos &&
+ "Model must be a simple filename.");
+ // Use P.begin() so that createUniqueEntity doesn't need to recreate Storage.
+ return createUniqueEntity(P.begin(), ResultFD, ResultPath,
+ true, owner_read | owner_write, Type);
+}
+
+static error_code
+createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD,
+ llvm::SmallVectorImpl<char> &ResultPath,
+ FSEntity Type) {
+ return createTemporaryFile(Prefix + "-%%%%%%." + Suffix, ResultFD, ResultPath,
+ Type);
+}
+
+
+error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix,
+ int &ResultFD,
+ SmallVectorImpl<char> &ResultPath) {
+ return createTemporaryFile(Prefix, Suffix, ResultFD, ResultPath, FS_File);
+}
+
+error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix,
+ SmallVectorImpl<char> &ResultPath) {
+ int Dummy;
+ return createTemporaryFile(Prefix, Suffix, Dummy, ResultPath, FS_Name);
+}
+
+
// This is a mkdtemp with a different pattern. We use createUniqueEntity mostly
// for consistency. We should try using mkdtemp.
error_code createUniqueDirectory(const Twine &Prefix,
OpenPOWER on IntegriCloud