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 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)tmpnam.3 8.2 (Berkeley) 11/17/93
33 .\" $FreeBSD: src/lib/libc/stdio/tmpnam.3,v 1.20 2007/03/16 21:46:24 maxim Exp $
42 .Nd temporary file routines
64 returns a pointer to a stream associated with a file descriptor returned
67 The created file is unlinked before
69 returns, causing the file to be automatically deleted when the last
70 reference to it is closed.
71 The file is opened with the access value
73 If the environment variable
76 the file is created in the specified directory.
77 The default location, if
85 returns a pointer to a file name, in the
88 did not reference an existing file at some indeterminate point in the
91 is defined in the include file
97 the file name is copied to the buffer it references.
98 Otherwise, the file name is copied to a static buffer.
101 returns a pointer to the file name.
103 The buffer referenced by
105 is expected to be at least
109 is defined in the include file
117 but provides the ability to specify the directory which will
118 contain the temporary file and the file name prefix.
126 the environment variable
131 and finally, the current directory,
132 are tried, in the listed order, as directories in which to store the
139 is used to specify a file name prefix, which will be the
140 first part of the created file name.
144 allocates memory in which to store the file name; the returned pointer
145 may be used as a subsequent argument to
151 returns a pointer to an open file stream on success, and a
161 return a pointer to a file name on success, and a
171 the directory in which the temporary file is stored.
173 is ignored for processes
179 These interfaces are provided from System V and
183 Most historic implementations of these functions provide
184 only a limited number of possible temporary file names
186 before file names will start being recycled.
187 System V implementations of these functions
192 system call to determine whether or not the temporary file
194 This has obvious ramifications for setuid or setgid programs,
195 complicating the portable use of these interfaces in such programs.
199 interface should not be used in software expected to be used on other systems
200 if there is any possibility that the user does not wish the temporary file to
201 be publicly readable and writable.
206 may fail and set the global variable
208 for any of the errors specified for the library functions
218 for any of the errors specified for the library function
226 for any of the errors specified for the library functions
230 .Sh SECURITY CONSIDERATIONS
235 functions are susceptible to a race condition
236 occurring between the selection of the file name
237 and the creation of the file,
238 which allows malicious users
239 to potentially overwrite arbitrary files in the system,
240 depending on the level of privilege of the running program.
241 Additionally, there is no means by which
242 file permissions may be specified.
243 It is strongly suggested that
245 be used in place of these functions.
248 .Sh LEGACY DESCRIPTION
249 In legacy mode, the order directories are tried by the
251 function is different; the environment variable
253 (if defined) is used first.