source:
asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/temp/mktemp.c
Last change on this file was 352, checked in by , 6 years ago | |
---|---|
|
|
File size: 539 bytes |
Line | |
---|---|
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 | } |
Note:
See TracBrowser
for help on using the repository browser.