1 #include <u.h> 2 #include <libc.h> 3 4 char* mktemp(char * as)5mktemp(char *as) 6 { 7 char *s; 8 unsigned pid; 9 int i; 10 char err[ERRMAX]; 11 12 pid = getpid(); 13 s = as; 14 while(*s++) 15 ; 16 s--; 17 while(*--s == 'X') { 18 *s = pid % 10 + '0'; 19 pid = pid/10; 20 } 21 s++; 22 i = 'a'; 23 while(access(as, 0) != -1) { 24 if (i == 'z') 25 return "/"; 26 *s = i++; 27 } 28 err[0] = '\0'; 29 errstr(err, sizeof err); /* clear the error */ 30 return as; 31 } 32