1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| | #include <fcntl.h>
#include <string.h>
#include <errno.h>
#include "libc.h"
void __randname(char *);
int __mkostemps (char *template, int suffixlen, int flags)
{
size_t l = strlen(template);
char *x6 = template + l - suffixlen;
if(l - suffixlen < 6 || memcmp(x6, "XXXXXX", 6)) {
errno = EINVAL;
*template = 0;
return -1;
}
int fd, retries = 100;
while (retries--) {
__randname(x6);
if ((fd = open(template, flags | O_CREAT | O_EXCL, 0600))>=0)
return fd;
if (errno != EEXIST) return -1;
}
return -1;
}
weak_alias(__mkostemps, mkostemps);
LFS64(mkostemps);
|