tmpnam.c (403B)
1 #include <sys.h> 2 3 #include <stdio.h> 4 #include <string.h> 5 6 #include "../syscall.h" 7 8 #undef tmpnam 9 10 char * 11 tmpnam(char *s) 12 { 13 static char tmpl[] = _TMPNAME; 14 char *p, *beg; 15 16 17 for (beg = tmpl; *beg < '0' || *beg > '9'; ++beg) 18 ; 19 20 do { 21 for (p = beg; *p == '9'; *p++ = '0') 22 ; 23 if (*p == '\0') 24 return NULL; 25 ++*p; 26 } while (_access(tmpl, F_OK) == 0); 27 28 if (s) 29 strcpy(s, tmpl); 30 return tmpl; 31 }