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