[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 09:48:44 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG64e4dd329c0c: [libcxx] [test] Fix back-to-back use of get_temp_file_name() on Windows (authored by mstorsjo).

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.421948.patch
Type: text/x-patch
Size: 1020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220411/92f2f305/attachment.bin>


More information about the libcxx-commits mailing list