|
5 | 5 | #define TEST_NAMEX "<cwchar>, part 1"
|
6 | 6 |
|
7 | 7 | #include "tdefs.h"
|
| 8 | +#include "temp_file_name.h" |
8 | 9 | #include <assert.h>
|
9 | 10 | #include <cwchar>
|
10 | 11 | #include <stdarg.h>
|
|
13 | 14 |
|
14 | 15 | #pragma warning(disable : 4793) // function compiled as native
|
15 | 16 |
|
16 |
| -#define NO_TMPNAM_TESTS 1 |
17 |
| -#undef tmpnam |
18 |
| -#define tmpnam(x) _tempnam(".", "") |
19 | 17 |
|
20 | 18 | #undef clearerr // tested in stdio2.c
|
21 | 19 | #undef feof
|
@@ -101,7 +99,8 @@ void test_cpp() { // test C++ header
|
101 | 99 | int in1;
|
102 | 100 | long off;
|
103 | 101 |
|
104 |
| - assert((tn = CSTD tmpnam((char*) nullptr)) != nullptr); |
| 102 | + const auto temp_name = temp_file_name(); |
| 103 | + tn = temp_name.c_str(); |
105 | 104 | assert((pf = CSTD fopen(tn, "w+")) != nullptr);
|
106 | 105 | CHECK_INT(STDx fwide(pf, 0), 0);
|
107 | 106 | CHECK_INT(STDx fwprintf(pf, L"123\n"), 4);
|
@@ -141,19 +140,15 @@ void test_cpp() { // test C++ header
|
141 | 140 |
|
142 | 141 | CHECK(wmacs[1] < wmacs[0]);
|
143 | 142 |
|
144 |
| -#if NO_TMPNAM_TESTS |
145 |
| - char *tname, *tn; |
146 |
| - assert((tn = CSTD tmpnam((char*) nullptr)) != nullptr); |
147 |
| - tname = (char*) CSTD malloc(CSTD strlen(tn) + 1); |
| 143 | + char* tname; |
| 144 | + const char* tn; |
| 145 | + const auto temp_name1 = temp_file_name(); |
| 146 | + tn = temp_name1.c_str(); |
| 147 | + tname = (char*) CSTD malloc(CSTD strlen(tn) + 1); |
148 | 148 | CSTD strcpy(tname, tn);
|
149 | 149 |
|
150 |
| -#else // NO_TMPNAM_TESTS |
151 |
| - char tname[L_tmpnam], *tn; |
152 |
| - CHECK_PTR(CSTD tmpnam(tname), tname); |
153 |
| - assert(CSTD strlen(tname) < L_tmpnam); |
154 |
| -#endif // NO_TMPNAM_TESTS |
155 |
| - |
156 |
| - assert((tn = CSTD tmpnam((char*) nullptr)) != nullptr); |
| 150 | + const auto temp_name2 = temp_file_name(); |
| 151 | + tn = temp_name2.c_str(); |
157 | 152 | CHECK(CSTD strcmp(tn, tname) != 0);
|
158 | 153 | assert((pf = CSTD fopen(tname, "w")) != nullptr);
|
159 | 154 | CHECK_INT(STDx fgetwc(pf), wintval);
|
|
0 commit comments