[libcxx-commits] [PATCH] D122612: [libcxx] [test] Fix back-to-back use of get_temp_file_name() on Windows
Martin Storsjö via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Apr 11 07:05:42 PDT 2022
mstorsjo updated this revision to Diff 421916.
mstorsjo added a comment.
Made the temp file creation atomic by creating the suggested temp file with `_open(_O_CREAT | _O_EXCL)`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D122612/new/
https://reviews.llvm.org/D122612
Files:
libcxx/test/support/platform_support.h
Index: libcxx/test/support/platform_support.h
===================================================================
--- libcxx/test/support/platform_support.h
+++ libcxx/test/support/platform_support.h
@@ -39,6 +39,8 @@
#include <string>
#if defined(_WIN32)
# include <io.h> // _mktemp_s
+# include <fcntl.h> // _O_EXCL, ...
+# include <sys/stat.h> // _S_IREAD, ...
#else
# include <unistd.h> // 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122612.421916.patch
Type: text/x-patch
Size: 1020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220411/d85cf089/attachment-0001.bin>
More information about the libcxx-commits
mailing list