File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change 13
13
#include <stdlib.h>
14
14
#include <cmocka.h>
15
15
#include <limits.h>
16
- #if !_WIN32
16
+ #if _WIN32
17
+ #include <process.h>
18
+ #else
17
19
#include <unistd.h>
18
20
#endif
19
21
@@ -126,17 +128,30 @@ int setup(void **state)
126
128
return -1 ;
127
129
}
128
130
131
+ static char * temporary_name (void )
132
+ {
133
+ #if _WIN32
134
+ int pid = _getpid ();
135
+ #else
136
+ pid_t pid = getpid ();
137
+ #endif
138
+
139
+ char format [128 ];
140
+ snprintf (format , sizeof (format ), "zone.%d" , pid );
141
+ return tempnam (NULL , format );
142
+ }
143
+
129
144
static char * generate_include (const char * text )
130
145
{
131
146
for (int i = 0 ; i < 100 ; i ++ ) {
132
- char * path = tempnam ( NULL , "zone" );
147
+ char * path = temporary_name ( );
133
148
if (path ) {
134
149
FILE * handle = fopen (path , "wbx" );
135
150
if (handle ) {
136
- int result = fputs (text , handle );
151
+ int error = fputs (text , handle );
137
152
fflush (handle );
138
153
(void )fclose (handle );
139
- if (result != EOF )
154
+ if (error != EOF )
140
155
return path ;
141
156
}
142
157
free (path );
@@ -285,7 +300,7 @@ void the_include_that_wasnt(void **state)
285
300
286
301
(void )state ;
287
302
288
- char * non_include = tempnam ( NULL , "zone" );
303
+ char * non_include = temporary_name ( );
289
304
assert_non_null (non_include );
290
305
291
306
char buffer [16 ];
You can’t perform that action at this time.
0 commit comments