1987-03-31 10:45:53 +00:00
|
|
|
/* $Header$ */
|
1987-01-27 15:57:55 +00:00
|
|
|
/* mktemp - make a name for a temporary file */
|
|
|
|
|
|
|
|
char *mktemp(template)
|
|
|
|
char *template;
|
|
|
|
{
|
|
|
|
register int pid, k;
|
|
|
|
register char *p;
|
|
|
|
|
|
|
|
pid = getpid(); /* get process id as semi-unique number */
|
|
|
|
p = template;
|
|
|
|
while (*p) p++; /* find end of string */
|
|
|
|
|
|
|
|
/* Replace XXXXXX at end of template with pid. */
|
|
|
|
while (*--p == 'X') {
|
|
|
|
*p = '0' + (pid % 10);
|
|
|
|
pid /= 10;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
for (k = 'a'; k <= 'z'; k++) {
|
|
|
|
*p = k;
|
|
|
|
if (access(template, 0) < 0) {
|
|
|
|
return template;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return("/");
|
|
|
|
}
|