[libcxx-commits] [PATCH] D98526: [libcxx] [test] Fix the get_temp_file_name() function for mingw (alternative implementation)

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 12 09:39:31 PST 2021


mstorsjo created this revision.
mstorsjo added a reviewer: EricWF.
mstorsjo requested review of this revision.
Herald added a project: libc++.
Herald added a reviewer: libc++.

This is an alternative to D97456 <https://reviews.llvm.org/D97456>; this avoids including windows.h at
all.

Use the same codepaths as for MSVC. Mingw-w64 does have the _mktemp_s
function; on Vista and newer, msvcrt.dll does contain the function,
which ends up called. (Same thing in the UCRT.) In older versions of
msvcrt.dll (older than what libc++ supports), mingw-w64 provides a
fallback implementation.

This effectively reverts 23323e25f896cf44e6d4519ef38f066e45fe408f. That
commit tried to fix unspecified MinGW build breakage. The commit added
calls to GetTempPath and GetTempFileName, but those functions aren't
declared unless windows.h is included - and it isn't included, it wasn't
included back then and it isn't now.

Also simplify an ifdef condition; _WIN32 is defined on mingw too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98526

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
@@ -56,7 +56,7 @@
 #include <codecvt>
 #include <locale>
 #include <string>
-#if defined(_WIN32) || defined(__MINGW32__)
+#if defined(_WIN32)
 #   include <io.h> // _mktemp_s
 #else
 #   include <unistd.h> // close
@@ -73,13 +73,7 @@
 inline
 std::string get_temp_file_name()
 {
-#if defined(__MINGW32__)
-    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;
-#elif defined(_WIN32)
+#if defined(_WIN32)
     char Name[] = "libcxx.XXXXXX";
     if (_mktemp_s(Name, sizeof(Name)) != 0) abort();
     return Name;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98526.330282.patch
Type: text/x-patch
Size: 852 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210312/4b07d79c/attachment.bin>


More information about the libcxx-commits mailing list