summaryrefslogtreecommitdiffstats
path: root/src/cmd/postscript/common/tempnam.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/postscript/common/tempnam.c')
-rw-r--r--src/cmd/postscript/common/tempnam.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/cmd/postscript/common/tempnam.c b/src/cmd/postscript/common/tempnam.c
new file mode 100644
index 00000000..529025ed
--- /dev/null
+++ b/src/cmd/postscript/common/tempnam.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <errno.h>
+
+#if defined(V9) || defined(BSD4_2) || defined(plan9)
+char *tempnam(char *dir, char *pfx) {
+ int pid;
+ unsigned int len;
+ char *tnm, *malloc();
+ static int seq = 0;
+
+ pid = getpid();
+ len = strlen(dir) + strlen(pfx) + 10;
+ if ((tnm = malloc(len)) != NULL) {
+ sprintf(tnm, "%s", dir);
+ if (access(tnm, 7) == -1)
+ return(NULL);
+ do {
+ sprintf(tnm, "%s/%s%d%d", dir, pfx, pid, seq++);
+ errno = 0;
+ if (access(tnm, 7) == -1)
+ if (errno == ENOENT)
+ return(tnm);
+ } while (1);
+ }
+ return(tnm);
+}
+#endif