[PATCH] D19702: [libcxx] [test] Fix get_temp_file_name() to compile for Windows.

Stephan T. Lavavej via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 28 17:16:05 PDT 2016


STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

[libcxx] [test] Fix get_temp_file_name() to compile for Windows.

It was including <io.h> but attempting to use GetTempPath() and GetTempFileName(), which are provided by <windows.h>.

Instead of dragging in <windows.h> (which is large), we can use _mktemp_s() from <io.h>.

Fixes MSVC errors:
"error C2065: 'MAX_PATH': undeclared identifier"
"error C3861: 'GetTempPath': identifier not found"
"error C3861: 'GetTempFileName': identifier not found"

http://reviews.llvm.org/D19702

Files:
  test/support/platform_support.h

Index: test/support/platform_support.h
===================================================================
--- test/support/platform_support.h
+++ test/support/platform_support.h
@@ -53,7 +53,7 @@
 #include <stdlib.h>
 #include <string>
 #if defined(_WIN32) || defined(__MINGW32__)
-#include <io.h> // _mktemp
+#include <io.h> // _mktemp_s
 #else
 #include <unistd.h> // close
 #endif
@@ -71,11 +71,13 @@
 get_temp_file_name()
 {
 #if defined(_WIN32) || 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;
+    char Name[] = "libcxx.XXXXXX";
+
+    if (_mktemp_s(Name, sizeof(Name)) != 0) {
+        abort();
+    }
+
+    return Name;
 #else
     std::string Name;
     int FD = -1;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19702.55512.patch
Type: text/x-patch
Size: 844 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160429/5c01cc3d/attachment.bin>


More information about the cfe-commits mailing list