From: ceriel Date: Fri, 1 Feb 1991 10:31:03 +0000 (+0000) Subject: Added mktemp.c X-Git-Tag: release-5-5~1268 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=4a03769a4708fcb2c710b6d1f891995e64edd710;p=ack.git Added mktemp.c --- diff --git a/lang/cem/libcc.ansi/misc/.distr b/lang/cem/libcc.ansi/misc/.distr index 334b04a22..5aab4d88b 100644 --- a/lang/cem/libcc.ansi/misc/.distr +++ b/lang/cem/libcc.ansi/misc/.distr @@ -20,3 +20,4 @@ seekdir.c sleep.c telldir.c termcap.c +mktemp.c diff --git a/lang/cem/libcc.ansi/misc/LIST b/lang/cem/libcc.ansi/misc/LIST index 9544baf07..37407a345 100644 --- a/lang/cem/libcc.ansi/misc/LIST +++ b/lang/cem/libcc.ansi/misc/LIST @@ -18,3 +18,4 @@ rewinddir.c seekdir.c telldir.c isatty.c +mktemp.c diff --git a/lang/cem/libcc.ansi/misc/mktemp.c b/lang/cem/libcc.ansi/misc/mktemp.c new file mode 100644 index 000000000..0d1132877 --- /dev/null +++ b/lang/cem/libcc.ansi/misc/mktemp.c @@ -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("/"); +}