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
This commit is contained in:
Jonathan Roelofs 2014-08-19 13:56:56 +00:00
parent 802a353065
commit 1542a60c0b
1 changed files with 14 additions and 4 deletions

View File

@ -50,13 +50,23 @@ inline
std::string std::string
get_temp_file_name() get_temp_file_name()
{ {
std::string s("temp.XXXXXX");
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) #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 #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 #endif
return s;
} }
#endif // PLATFORM_SUPPORT_H #endif // PLATFORM_SUPPORT_H