Skip to content

Commit b153797

Browse files
committed
Include PID in temporary name
1 parent 8f19188 commit b153797

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tests/include.c

+17-4
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,30 @@ int setup(void **state)
126126
return -1;
127127
}
128128

129+
static char *temporary_name(void)
130+
{
131+
#if _WIN32
132+
int pid = _getpid();
133+
#else
134+
pid_t pid = getpid();
135+
#endif
136+
137+
char format[128];
138+
snprintf(format, sizeof(format), "zone.%d", pid);
139+
return tempnam(NULL, format);
140+
}
141+
129142
static char *generate_include(const char *text)
130143
{
131144
for (int i=0; i < 100; i++) {
132-
char *path = tempnam(NULL, "zone");
145+
char *path = temporary_name();
133146
if (path) {
134147
FILE *handle = fopen(path, "wbx");
135148
if (handle) {
136-
int result = fputs(text, handle);
149+
int error = fputs(text, handle);
137150
fflush(handle);
138151
(void)fclose(handle);
139-
if (result != EOF)
152+
if (error != EOF)
140153
return path;
141154
}
142155
free(path);
@@ -285,7 +298,7 @@ void the_include_that_wasnt(void **state)
285298

286299
(void)state;
287300

288-
char *non_include = tempnam(NULL, "zone");
301+
char *non_include = temporary_name();
289302
assert_non_null(non_include);
290303

291304
char buffer[16];

0 commit comments

Comments
 (0)