]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/stdio/tmpnam.3
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.git] / lib / libc / stdio / tmpnam.3
1 .\" Copyright (c) 1988, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the American National Standards Committee X3, on Information
6 .\" Processing Systems.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
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.
23 .\"
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
34 .\" SUCH DAMAGE.
35 .\"
36 .\"     @(#)tmpnam.3    8.2 (Berkeley) 11/17/93
37 .\" $FreeBSD$
38 .\"
39 .Dd November 17, 1993
40 .Dt TMPFILE 3
41 .Os
42 .Sh NAME
43 .Nm tempnam ,
44 .Nm tmpfile ,
45 .Nm tmpnam
46 .Nd temporary file routines
47 .Sh SYNOPSIS
48 .Fd #include <stdio.h>
49 .Ft FILE *
50 .Fn tmpfile void
51 .Ft char *
52 .Fn tmpnam "char *str"
53 .Ft char *
54 .Fn tempnam "const char *tmpdir" "const char *prefix"
55 .Sh DESCRIPTION
56 The
57 .Fn tmpfile
58 function
59 returns a pointer to a stream associated with a file descriptor returned
60 by the routine
61 .Xr mkstemp 3 .
62 The created file is unlinked before
63 .Fn tmpfile
64 returns, causing the file to be automatically deleted when the last
65 reference to it is closed.
66 The file is opened with the access value
67 .Ql w+ .
68 .Pp
69 The
70 .Fn tmpnam
71 function
72 returns a pointer to a file name, in the
73 .Dv P_tmpdir
74 directory, which
75 did not reference an existing file at some indeterminate point in the
76 past.
77 .Dv P_tmpdir
78 is defined in the include file
79 .Aq Pa stdio.h .
80 If the argument
81 .Fa str
82 is
83 .Pf non- Dv NULL ,
84 the file name is copied to the buffer it references.
85 Otherwise, the file name is copied to a static buffer.
86 In either case,
87 .Fn tmpnam
88 returns a pointer to the file name.
89 .Pp
90 The buffer referenced by 
91 .Fa str
92 is expected to be at least
93 .Dv L_tmpnam
94 bytes in length.
95 .Dv L_tmpnam
96 is defined in the include file
97 .Aq Pa stdio.h .
98 .Pp
99 The
100 .Fn tempnam
101 function
102 is similar to
103 .Fn tmpnam ,
104 but provides the ability to specify the directory which will
105 contain the temporary file and the file name prefix.
106 .Pp
107 The environment variable
108 .Ev TMPDIR
109 (if set), the argument
110 .Fa tmpdir
111 (if
112 .Pf non- Dv NULL ) ,
113 the directory
114 .Dv P_tmpdir ,
115 and the directory
116 .Pa /tmp
117 are tried, in the listed order, as directories in which to store the
118 temporary file.
119 .Pp
120 The argument
121 .Fa prefix ,
122 if
123 .Pf non- Dv NULL ,
124 is used to specify a file name prefix, which will be the
125 first part of the created file name.
126 .Fn Tempnam
127 allocates memory in which to store the file name; the returned pointer
128 may be used as a subsequent argument to
129 .Xr free 3 .
130 .Sh RETURN VALUES
131 The
132 .Fn tmpfile
133 function
134 returns a pointer to an open file stream on success, and a
135 .Dv NULL
136 pointer
137 on error.
138 .Pp
139 The
140 .Fn tmpnam
141 and
142 .Fn tempfile
143 functions
144 return a pointer to a file name on success, and a
145 .Dv NULL
146 pointer
147 on error.
148 .Sh ERRORS
149 The
150 .Fn tmpfile
151 function
152 may fail and set the global variable
153 .Va errno
154 for any of the errors specified for the library functions
155 .Xr fdopen 3
156 or
157 .Xr mkstemp 3 .
158 .Pp
159 The
160 .Fn tmpnam
161 function
162 may fail and set
163 .Va errno
164 for any of the errors specified for the library function
165 .Xr mktemp 3 .
166 .Pp
167 The
168 .Fn tempnam
169 function
170 may fail and set
171 .Va errno
172 for any of the errors specified for the library functions
173 .Xr malloc 3
174 or
175 .Xr mktemp 3 .
176 .Sh SEE ALSO
177 .Xr mkstemp 3 ,
178 .Xr mktemp 3
179 .Sh STANDARDS
180 The
181 .Fn tmpfile
182 and
183 .Fn tmpnam
184 functions
185 conform to
186 .St -ansiC .
187 .Sh BUGS
188 These interfaces are provided for System V and
189 .Tn ANSI
190 compatibility only.
191 The
192 .Xr mkstemp 3
193 interface is strongly preferred.
194 .Pp
195 There are four important problems with these interfaces (as well as
196 with the historic
197 .Xr mktemp 3
198 interface).
199 First, there is an obvious race between file name selection and file
200 creation and deletion.
201 Second, most historic implementations provide only a limited number
202 of possible temporary file names (usually 26) before file names will
203 start being recycled.
204 Third, the System V implementations of these functions (and of
205 .Xr mktemp 3 )
206 use the
207 .Xr access 2
208 function to determine whether or not the temporary file may be created.
209 This has obvious ramifications for setuid or setgid programs, complicating
210 the portable use of these interfaces in such programs.
211 Finally, there is no specification of the permissions with which the
212 temporary files are created.
213 .Pp
214 This implementation does not have these flaws, but portable software
215 cannot depend on that.
216 In particular, the
217 .Fn tmpfile
218 interface should not be used in software expected to be used on other systems
219 if there is any possibility that the user does not wish the temporary file to
220 be publicly readable and writable.