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;


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;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to