OLD | NEW |
(Empty) | |
| 1 #include <stdio.h> |
| 2 #include <fcntl.h> |
| 3 #include <errno.h> |
| 4 #include <sys/stat.h> |
| 5 #include <string.h> |
| 6 #include "syscall.h" |
| 7 |
| 8 #define MAXTRIES 100 |
| 9 |
| 10 char *__randname(char *); |
| 11 |
| 12 char *tmpnam(char *buf) |
| 13 { |
| 14 static char internal[L_tmpnam]; |
| 15 char s[] = "/tmp/tmpnam_XXXXXX"; |
| 16 int try; |
| 17 int r; |
| 18 for (try=0; try<MAXTRIES; try++) { |
| 19 __randname(s+12); |
| 20 #ifdef SYS_lstat |
| 21 r = __syscall(SYS_lstat, s, &(struct stat){0}); |
| 22 #else |
| 23 r = __syscall(SYS_fstatat, AT_FDCWD, s, |
| 24 &(struct stat){0}, AT_SYMLINK_NOFOLLOW); |
| 25 #endif |
| 26 if (r == -ENOENT) return strcpy(buf ? buf : internal, s); |
| 27 } |
| 28 return 0; |
| 29 } |
OLD | NEW |