eliminate protected-visibility data in libc.so with vis.h preinclude
[musl.git] / src / temp / mktemp.c
blob4ab0df2069ac6d0c685ea2265f15d40596392217
1 #define _GNU_SOURCE
2 #include <string.h>
3 #include <stdlib.h>
4 #include <errno.h>
5 #include <sys/stat.h>
7 char *__randname(char *);
9 char *mktemp(char *template)
11 size_t l = strlen(template);
12 int retries = 100;
13 struct stat st;
15 if (l < 6 || memcmp(template+l-6, "XXXXXX", 6)) {
16 errno = EINVAL;
17 *template = 0;
18 return template;
21 do {
22 __randname(template+l-6);
23 if (stat(template, &st)) {
24 if (errno != ENOENT) *template = 0;
25 return template;
27 } while (--retries);
29 *template = 0;
30 errno = EEXIST;
31 return template;