|
|
1.1 root 1: /*
2: * libc/stdio/tmpnam.c
3: * ANSI-compliant C standard i/o library.
4: * tmpnam()
5: * ANSI 4.9.4.4.
6: * Generate a temporary file name a la SV.
7: * The name (generated by mktemp()) is of the form "/tmp/t<pid>x",
8: * where <pid> is the 5-digit pid and x is an ASCII character.
9: */
10:
11: #include <stdio.h>
12: #include <string.h>
13:
14: extern char *mktemp();
15:
16: #ifdef GEMDOS
17: #define FSPATHSEP "\\"
18: #ifndef P_tmpdir
19: #define P_tmpdir "\\tmp"
20: #endif
21: #endif
22: #ifdef DOS
23: #define FSPATHSEP "\\"
24: #ifndef P_tmpdir
25: #define P_tmpdir "\\tmp"
26: #endif
27: #endif
28: #ifndef FSPATHSEP
29: #define FSPATHSEP "/"
30: #ifndef P_tmpdir
31: #define P_tmpdir "/tmp"
32: #endif
33: #endif
34: #ifndef L_tmpnam
35: #define L_tmpnam 64
36: #endif
37: #define TEMPLATE "tXXXXXX"
38:
39: char *
40: tmpnam(s) register char *s;
41: {
42: static char namebuf[L_tmpnam];
43: char *name;
44:
45: if (s == NULL)
46: s = namebuf;
47: for (;;) {
48: strcpy(s, P_tmpdir);
49: strcat(s, FSPATHSEP);
50: strcat(s, TEMPLATE);
51: name = mktemp(s);
52: if (access(name, 0) == -1)
53: break;
54: }
55: return name;
56: }
57:
58: /* end of libc/stdio/tmpnam.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.