Added mktemp.c
This commit is contained in:
parent
977d93dc67
commit
4a03769a47
3 changed files with 32 additions and 0 deletions
|
@ -20,3 +20,4 @@ seekdir.c
|
|||
sleep.c
|
||||
telldir.c
|
||||
termcap.c
|
||||
mktemp.c
|
||||
|
|
|
@ -18,3 +18,4 @@ rewinddir.c
|
|||
seekdir.c
|
||||
telldir.c
|
||||
isatty.c
|
||||
mktemp.c
|
||||
|
|
30
lang/cem/libcc.ansi/misc/mktemp.c
Normal file
30
lang/cem/libcc.ansi/misc/mktemp.c
Normal 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("/");
|
||||
}
|
Loading…
Reference in a new issue