Give libcxx tests temporary filenames that are actually unique.

This fixes a race condition on temp file name creation.

http://reviews.llvm.org/D4962


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@215977 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jonathan Roelofs 2014-08-19 13:56:56 +00:00
parent 6661ad10f2
commit 6f10d47bbc

View File

@ -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