1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1991-02-01 10:31:03 +00:00
|
|
|
/* mktemp - make a name for a temporary file; only here for backwards compat */
|
|
|
|
/* no _-protected system-calls? */
|
|
|
|
|
|
|
|
unsigned int getpid(void);
|
2018-06-21 20:33:47 +00:00
|
|
|
int access(char*, int);
|
1991-02-01 10:31:03 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
char* mktemp(char* template)
|
1991-02-01 10:31:03 +00:00
|
|
|
{
|
2018-06-21 20:33:47 +00:00
|
|
|
register int pid, k;
|
|
|
|
register char* p;
|
1991-02-01 10:31:03 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
pid = getpid(); /* get process id as semi-unique number */
|
|
|
|
p = template;
|
|
|
|
while (*p)
|
|
|
|
p++; /* find end of string */
|
1991-02-01 10:31:03 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
/* Replace XXXXXX at end of template with pid. */
|
|
|
|
while (*--p == 'X')
|
|
|
|
{
|
|
|
|
*p = '0' + (pid % 10);
|
|
|
|
pid /= 10;
|
1991-02-01 10:31:03 +00:00
|
|
|
}
|
2018-06-21 20:33:47 +00:00
|
|
|
p++;
|
|
|
|
for (k = 'a'; k <= 'z'; k++)
|
|
|
|
{
|
|
|
|
*p = k;
|
|
|
|
if (access(template, 0) < 0)
|
|
|
|
{
|
|
|
|
return template;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ("/");
|
1991-02-01 10:31:03 +00:00
|
|
|
}
|