From: Martin Storsjö Date: Fri, 12 Mar 2021 15:58:30 +0000 (+0200) Subject: [libcxx] [test] Simplify get_temp_file_name() for mingw X-Git-Tag: upstream/15.0.7~32019 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c5a74c0890f41e339c13e2a32cc89828c1451768;p=platform%2Fupstream%2Fllvm.git [libcxx] [test] Simplify get_temp_file_name() for mingw 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 (and d07e5c23b40078dcae13f76b091c9e18763ae44a). That commit tried to fix unspecified MinGW build breakage. This reduces the risk of temp name collisions between processes (when running multiple tests in parallel); the path returned by GetTempFileName can easily collide with other similar paths. (_mktemp_s on the other hand tries to avoid such clashes by using the process id as part of the uniqueness seed.) This avoids stray random failures in fstreams tests in mingw configurations. Differential Revision: https://reviews.llvm.org/D98526 --- diff --git a/libcxx/test/support/platform_support.h b/libcxx/test/support/platform_support.h index 83e291d..f8183d2 100644 --- a/libcxx/test/support/platform_support.h +++ b/libcxx/test/support/platform_support.h @@ -46,9 +46,7 @@ #include #include #if defined(_WIN32) -# define WIN32_LEAN_AND_MEAN // Reduce overhead of including windows.h # include // _mktemp_s -# include // MAX_PATH, GetTempPath, GetTempFileName #else # include // close #endif @@ -63,13 +61,7 @@ extern "C" { 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;