Added mktemp.c
authorceriel <none@none>
Fri, 1 Feb 1991 10:31:03 +0000 (10:31 +0000)
committerceriel <none@none>
Fri, 1 Feb 1991 10:31:03 +0000 (10:31 +0000)
lang/cem/libcc.ansi/misc/.distr
lang/cem/libcc.ansi/misc/LIST
lang/cem/libcc.ansi/misc/mktemp.c [new file with mode: 0644]

index 334b04a..5aab4d8 100644 (file)
@@ -20,3 +20,4 @@ seekdir.c
 sleep.c
 telldir.c
 termcap.c
+mktemp.c
index 9544baf..37407a3 100644 (file)
@@ -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 (file)
index 0000000..0d11328
--- /dev/null
@@ -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("/");
+}