diff --git a/libcxx/test/support/platform_support.h b/libcxx/test/support/platform_support.h --- a/libcxx/test/support/platform_support.h +++ b/libcxx/test/support/platform_support.h @@ -39,6 +39,8 @@ #include #if defined(_WIN32) # include // _mktemp_s +# include // _O_EXCL, ... +# include // _S_IREAD, ... #else # include // close #endif @@ -54,9 +56,18 @@ std::string get_temp_file_name() { #if defined(_WIN32) - char Name[] = "libcxx.XXXXXX"; - if (_mktemp_s(Name, sizeof(Name)) != 0) abort(); - return Name; + while (true) { + char Name[] = "libcxx.XXXXXX"; + if (_mktemp_s(Name, sizeof(Name)) != 0) abort(); + int fd = _open(Name, _O_RDWR | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE); + if (fd != -1) { + _close(fd); + return Name; + } + if (errno == EEXIST) + continue; + abort(); + } #else std::string Name; int FD = -1;