1 #include <stdio.h> 2 #include <errno.h> 3 4 #if defined(V9) || defined(BSD4_2) || defined(plan9) 5 char *tempnam(char *dir, char *pfx) { 6 int pid; 7 unsigned int len; 8 char *tnm, *malloc(); 9 static int seq = 0; 10 11 pid = getpid(); 12 len = strlen(dir) + strlen(pfx) + 10; 13 if ((tnm = malloc(len)) != NULL) { 14 sprintf(tnm, "%s", dir); 15 if (access(tnm, 7) == -1) 16 return(NULL); 17 do { 18 sprintf(tnm, "%s/%s%d%d", dir, pfx, pid, seq++); 19 errno = 0; 20 if (access(tnm, 7) == -1) 21 if (errno == ENOENT) 22 return(tnm); 23 } while (1); 24 } 25 return(tnm); 26 } 27 #endif 28