summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Path.cpp
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-03-19 14:19:58 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-03-19 14:19:58 +0000
commit8418576304be789c95eed11005afb3111cf9cd95 (patch)
tree6c4ca199ff406b4b45c6ad943a42d3707593cc97 /llvm/lib/Support/Path.cpp
parent2ad19016c086d1915a8e96e2a63ca291719300ee (diff)
downloadbcm5719-llvm-8418576304be789c95eed11005afb3111cf9cd95.tar.gz
bcm5719-llvm-8418576304be789c95eed11005afb3111cf9cd95.zip
Changed createTemporaryFile without FD to actually create a file.
Summary: This commit changes semantics of createUniqueFile and createTemporaryFile variants that do not return file descriptors. Previously they only checked if files exist, therefore being subject to race conditions. Now they will create an empty file to avoid them. Functions that do not create a file are now called getPotentiallyUniqueTempFileName and getPotentiallyUniqueFileName. Reviewers: klimek, bkramer, krasimir, JDevlieghere, espindola Reviewed By: klimek Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D36827 llvm-svn: 327851
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r--llvm/lib/Support/Path.cpp39
1 files changed, 32 insertions, 7 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index f229f23a4f8..ec8a5ca98e5 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -757,9 +757,15 @@ std::error_code createUniqueFile(const Twine &Model, int &ResultFd,
}
std::error_code createUniqueFile(const Twine &Model,
- SmallVectorImpl<char> &ResultPath) {
- int Dummy;
- return createUniqueEntity(Model, Dummy, ResultPath, false, 0, FS_Name);
+ SmallVectorImpl<char> &ResultPath,
+ unsigned Mode) {
+ int FD;
+ auto EC = createUniqueFile(Model, FD, ResultPath, Mode);
+ if (EC)
+ return EC;
+ // FD is only needed to avoid race conditions. Close it right away.
+ close(FD);
+ return EC;
}
static std::error_code
@@ -794,8 +800,13 @@ std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix,
std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix,
SmallVectorImpl<char> &ResultPath) {
- int Dummy;
- return createTemporaryFile(Prefix, Suffix, Dummy, ResultPath, FS_Name);
+ int FD;
+ auto EC = createTemporaryFile(Prefix, Suffix, FD, ResultPath);
+ if (EC)
+ return EC;
+ // FD is only needed to avoid race conditions. Close it right away.
+ close(FD);
+ return EC;
}
@@ -804,8 +815,22 @@ std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix,
std::error_code createUniqueDirectory(const Twine &Prefix,
SmallVectorImpl<char> &ResultPath) {
int Dummy;
- return createUniqueEntity(Prefix + "-%%%%%%", Dummy, ResultPath,
- true, 0, FS_Dir);
+ return createUniqueEntity(Prefix + "-%%%%%%", Dummy, ResultPath, true, 0,
+ FS_Dir);
+}
+
+std::error_code
+getPotentiallyUniqueFileName(const Twine &Model,
+ SmallVectorImpl<char> &ResultPath) {
+ int Dummy;
+ return createUniqueEntity(Model, Dummy, ResultPath, false, 0, FS_Name);
+}
+
+std::error_code
+getPotentiallyUniqueTempFileName(const Twine &Prefix, StringRef Suffix,
+ SmallVectorImpl<char> &ResultPath) {
+ int Dummy;
+ return createTemporaryFile(Prefix, Suffix, Dummy, ResultPath, FS_Name);
}
static std::error_code make_absolute(const Twine &current_directory,
OpenPOWER on IntegriCloud