move msghdr and cmsghdr out of bits/socket.h
[musl.git] / src / temp / mktemp.c
blob7b3d2648b20676eb25fd451ea26db93ef8ca8b65
1 #define _GNU_SOURCE
2 #include <string.h>
3 #include <stdlib.h>
4 #include <errno.h>
5 #include <sys/stat.h>
7 char *mktemp(char *template)
9 size_t l = strlen(template);
10 int retries = 100;
11 struct stat st;
13 if (l < 6 || memcmp(template+l-6, "XXXXXX", 6)) {
14 errno = EINVAL;
15 *template = 0;
16 return template;
19 do {
20 __randname(template+l-6);
21 if (stat(template, &st)) {
22 if (errno != ENOENT) *template = 0;
23 return template;
25 } while (--retries);
27 *template = 0;
28 errno = EEXIST;
29 return template;