projects
/
oweals
/
musl.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
add __sigsetjmp ABI-compat alias for sigsetjmp
[oweals/musl.git]
/
src
/
temp
/
mktemp.c
1
#define _GNU_SOURCE
2
#include <string.h>
3
#include <stdlib.h>
4
#include <errno.h>
5
#include <sys/stat.h>
6
7
char *__randname(char *);
8
9
char *mktemp(char *template)
10
{
11
size_t l = strlen(template);
12
int retries = 100;
13
struct stat st;
14
15
if (l < 6 || memcmp(template+l-6, "XXXXXX", 6)) {
16
errno = EINVAL;
17
*template = 0;
18
return template;
19
}
20
21
do {
22
__randname(template+l-6);
23
if (stat(template, &st)) {
24
if (errno != ENOENT) *template = 0;
25
return template;
26
}
27
} while (--retries);
28
29
*template = 0;
30
errno = EEXIST;
31
return template;
32
}