|
|
1.1 root 1: .\" Copyright (c) 1988 The Regents of the University of California.
2: .\" All rights reserved.
3: .\"
4: .\" Redistribution and use in source and binary forms are permitted provided
5: .\" that: (1) source distributions retain this entire copyright notice and
6: .\" comment, and (2) distributions including binaries display the following
7: .\" acknowledgement: ``This product includes software developed by the
8: .\" University of California, Berkeley and its contributors'' in the
9: .\" documentation or other materials provided with the distribution and in
10: .\" all advertising materials mentioning features or use of this software.
11: .\" Neither the name of the University nor the names of its contributors may
12: .\" be used to endorse or promote products derived from this software without
13: .\" specific prior written permission.
14: .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
15: .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
16: .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17: .\"
18: .\" @(#)tmpnam.3 5.10 (Berkeley) 6/22/90
19: .\"
20: .TH TMPFILE 3 "June 22, 1990"
21: .UC 7
22: .SH NAME
23: tempnam, tmpfile, tmpnam \- temporary file routines
24: .SH SYNOPSIS
25: .nf
26: .ft B
27: #include <stdio.h>
28:
29: FILE *
30: tmpfile(void);
31:
32: char *
33: tmpnam(char *str);
34:
35: char *
36: tempnam(const char *tmpdir, const char *prefix);
37: .ft R
38: .fi
39: .SH DESCRIPTION
40: .I Tmpfile
41: opens a file using a file name generated by the routine
42: .IR tmpnam (3),
43: and returns a pointer to the stream associated with the file.
44: The created file is unlinked before
45: .I tmpfile
46: returns, causing the contents of the file to be deleted automatically
47: when the last reference to it is closed.
48: The file is opened with the access value ``w+''.
49: If
50: .I tmpnam
51: returns NULL, or if
52: .I tmpfile
53: is unable to open the file, a NULL pointer is returned.
54: .PP
55: .I Tmpnam
56: returns a pointer to a file name, in the directory ``/usr/tmp'', which
57: did not reference an existing file at some indeterminate point in the
58: past.
59: If the argument
60: .I s
61: is non-NULL, this file name is copied to the buffer it references.
62: Otherwise, memory to contain this file name is allocated by
63: .IR tmpnam .
64: In either case,
65: .I tmpnam
66: returns a pointer to the file name; in the latter case, the return
67: value may be used as a subsequent argument to
68: .IR free (3).
69: .PP
70: In the current implementation, the memory buffer referenced by
71: .I s
72: must be at least 16 bytes long.
73: .PP
74: .I Tempnam
75: is similar to
76: .I tmpnam,
77: but provides the ability to specify the directory which will
78: contain the temporary file and the file name prefix.
79: .PP
80: The environmental variable ``TMPDIR'' (if set), the argument
81: .I dir
82: (if non-NULL), the directory ``/usr/tmp'' and the directory ``/tmp''
83: are tried, in the listed order, as directories in which to store the
84: temporary file.
85: .I Tempnam
86: allocates memory in which to store the file name; the returned pointer
87: may be used as a subsequent argument to
88: .IR free (3).
89: The argument
90: .IR prefix ,
91: if non-NULL, is used to specify a file name prefix, which will be the
92: first part of the created file name.
93: .PP
94: .I Tmpnam
95: and
96: .I tempname
97: return a NULL pointer if unable to allocate memory or find a file
98: which may be created.
99: .PP
100: The manifest constants ``TMP_MAX'', ``P_tmpdir'' and ``L_tmpnam'',
101: documented for the routines
102: .I tmpnam
103: and
104: .I tempnam
105: in other systems, are not available in this implementation.
106: If the source code requires them, simply use:
107: .sp
108: .RS
109: #define TMP_MAX 308915776
110: .br
111: #define P_tmpdir "/usr/tmp"
112: .br
113: #define L_tmpnam 1024
114: .RE
115: .PP
116: .SH BUGS
117: These interfaces are provided for System V compatibility only.
118: The
119: .IR mkstemp (3)
120: interface is strongly preferred.
121: .PP
122: There are three important problems with these interfaces (as well as
123: with the historic
124: .IR mktemp (3)
125: interface).
126: First, there is an obvious race between file name selection and file
127: creation.
128: Second, most implementations provide only a limited number (usually
129: 26) of possible temporary file names before file names will start being
130: recycled.
131: Third, the System V implementations of these functions (and
132: .IR mktemp )
133: use the
134: .IR access (2)
135: system call to determine whether or not the temporary file may be created.
136: This has obvious ramifications for setuid or setgid programs, complicating
137: the portable use of these interfaces in such programs.
138: .PP
139: The
140: .IR mkstemp (3)
141: interface has none of these problems;
142: the
143: .IR mktemp(3)
144: implementation in this system suffers only from the race condition described
145: above.
146: .PP
147: The
148: .I tmpfile
149: interface should not be used if there is any possibility that the user
150: does not wish the temporary file to be publicly readable or writable.
151: .PP
152: .SH SEE ALSO
153: fopen(3), mkstemp(3), mktemp(3)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.