summaryrefslogtreecommitdiffstats
path: root/libcxx/test
diff options
context:
space:
mode:
authorJonathan Roelofs <jonathan@codesourcery.com>2014-08-19 13:56:56 +0000
committerJonathan Roelofs <jonathan@codesourcery.com>2014-08-19 13:56:56 +0000
commit1542a60c0bbb8534b949128dd43df5d940e47eb2 (patch)
tree257468c51aa396fd2da73ad98d8d38f70362aee3 /libcxx/test
parent802a3530658ff49274e2ad5087bbb71bed694fe5 (diff)
downloadbcm5719-llvm-1542a60c0bbb8534b949128dd43df5d940e47eb2.tar.gz
bcm5719-llvm-1542a60c0bbb8534b949128dd43df5d940e47eb2.zip
Give libcxx tests temporary filenames that are actually unique.
This fixes a race condition on temp file name creation. http://reviews.llvm.org/D4962 llvm-svn: 215977
Diffstat (limited to 'libcxx/test')
-rw-r--r--libcxx/test/support/platform_support.h18
1 files changed, 14 insertions, 4 deletions
diff --git a/libcxx/test/support/platform_support.h b/libcxx/test/support/platform_support.h
index 9ae2ae7cb2e..7b1ee8a8db4 100644
--- a/libcxx/test/support/platform_support.h
+++ b/libcxx/test/support/platform_support.h
@@ -50,13 +50,23 @@ inline
std::string
get_temp_file_name()
{
- std::string s("temp.XXXXXX");
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- _mktemp(&s[0]);
+ char Path[MAX_PATH+1];
+ char FN[MAX_PATH+1];
+ do { } while (0 == GetTempPath(MAX_PATH+1, Path));
+ do { } while (0 == GetTempFileName(Path, "libcxx", 0, FN));
+ return FN;
#else
- mktemp(&s[0]);
+ std::string Name;
+ int FD = -1;
+ do {
+ Name = "libcxx.XXXXXX";
+ FD = mkstemp(&Name[0]);
+ assert(errno != EINVAL && "Something is wrong with the mkstemp's argument");
+ } while (FD == -1 || errno == EEXIST);
+ close(FD);
+ return Name;
#endif
- return s;
}
#endif // PLATFORM_SUPPORT_H
OpenPOWER on IntegriCloud