Added mktemp.c

This commit is contained in:
ceriel 1991-02-01 10:31:03 +00:00
parent 977d93dc67
commit 4a03769a47
3 changed files with 32 additions and 0 deletions

View file

@ -20,3 +20,4 @@ seekdir.c
sleep.c
telldir.c
termcap.c
mktemp.c

View file

@ -18,3 +18,4 @@ rewinddir.c
seekdir.c
telldir.c
isatty.c
mktemp.c

View file

@ -0,0 +1,30 @@
/* $Header$ */
/* mktemp - make a name for a temporary file; only here for backwards compat */
/* no _-protected system-calls? */
unsigned int getpid(void);
int access(char *, int);
char *mktemp(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("/");
}