1 .\" Copyright (c) 1988, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the American National Standards Committee X3, on Information
6 .\" Processing Systems.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. All advertising materials mentioning features or use of this software
17 .\" must display the following acknowledgement:
18 .\" This product includes software developed by the University of
19 .\" California, Berkeley and its contributors.
20 .\" 4. Neither the name of the University nor the names of its contributors
21 .\" may be used to endorse or promote products derived from this software
22 .\" without specific prior written permission.
24 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .\" @(#)tmpnam.3 8.2 (Berkeley) 11/17/93
46 .Nd temporary file routines
50 .Fd #include <stdio.h>
54 .Fn tmpnam "char *str"
56 .Fn tempnam "const char *tmpdir" "const char *prefix"
61 returns a pointer to a stream associated with a file descriptor returned
64 The created file is unlinked before
66 returns, causing the file to be automatically deleted when the last
67 reference to it is closed.
68 The file is opened with the access value
74 returns a pointer to a file name, in the
77 did not reference an existing file at some indeterminate point in the
80 is defined in the include file
86 the file name is copied to the buffer it references.
87 Otherwise, the file name is copied to a static buffer.
90 returns a pointer to the file name.
92 The buffer referenced by
94 is expected to be at least
98 is defined in the include file
106 but provides the ability to specify the directory which will
107 contain the temporary file and the file name prefix.
109 The environment variable
111 (if set), the argument
119 are tried, in the listed order, as directories in which to store the
126 is used to specify a file name prefix, which will be the
127 first part of the created file name.
129 allocates memory in which to store the file name; the returned pointer
130 may be used as a subsequent argument to
136 returns a pointer to an open file stream on success, and a
146 return a pointer to a file name on success, and a
154 may fail and set the global variable
156 for any of the errors specified for the library functions
166 for any of the errors specified for the library function
174 for any of the errors specified for the library functions
190 These interfaces are provided for System V and
195 interface is strongly preferred.
197 There are four important problems with these interfaces (as well as
201 First, there is an obvious race between file name selection and file
202 creation and deletion.
203 Second, most historic implementations provide only a limited number
204 of possible temporary file names (usually 26) before file names will
205 start being recycled.
206 Third, the System V implementations of these functions (and of
210 function to determine whether or not the temporary file may be created.
211 This has obvious ramifications for setuid or setgid programs, complicating
212 the portable use of these interfaces in such programs.
213 Finally, there is no specification of the permissions with which the
214 temporary files are created.
216 This implementation does not have these flaws, but portable software
217 cannot depend on that.
220 interface should not be used in software expected to be used on other systems
221 if there is any possibility that the user does not wish the temporary file to
222 be publicly readable and writable.