1 #include <stdio.h> 2 #include <fcntl.h> 3 #include <stdlib.h> 4 #include <unsupported_api.h> 5 6 #include "stdio_impl.h" 7 8 #define MAXTRIES 100 9 tmpfile(void)10FILE *tmpfile(void) 11 { 12 char s[] = "/tmp/tmpfile_XXXXXX"; 13 int fd; 14 FILE *f; 15 int try; 16 unsupported_api(__FUNCTION__); 17 for (try=0; try<MAXTRIES; try++) { 18 __randname(s+13); 19 fd = sys_open(s, O_RDWR|O_CREAT|O_EXCL, 0600); 20 if (fd >= 0) { 21 #ifdef SYS_unlink 22 __syscall(SYS_unlink, s); 23 #else 24 __syscall(SYS_unlinkat, AT_FDCWD, s, 0); 25 #endif 26 f = __fdopen(fd, "w+"); 27 if (!f) __syscall(SYS_close, fd); 28 return f; 29 } 30 } 31 return 0; 32 } 33 34 weak_alias(tmpfile, tmpfile64); 35