mount_setattr.2: Rename 'path' to 'pathname'
[man-pages.git] / man3 / tmpnam.3
blob625dfbe764a19a5cd765093ef2429a6504c5e9d2
1 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" 2003-11-15, aeb, added tmpnam_r
26 .\"
27 .TH TMPNAM 3  2021-03-22 "" "Linux Programmer's Manual"
28 .SH NAME
29 tmpnam, tmpnam_r \- create a name for a temporary file
30 .SH SYNOPSIS
31 .nf
32 .B #include <stdio.h>
33 .PP
34 .BI "char *tmpnam(char *" s );
35 .BI "char *tmpnam_r(char *" s );
36 .fi
37 .PP
38 .RS -4
39 Feature Test Macro Requirements for glibc (see
40 .BR feature_test_macros (7)):
41 .RE
42 .PP
43 .BR tmpnam_r ()
44 .nf
45     Since glibc 2.19:
46         _DEFAULT_SOURCE
47     Up to and including glibc 2.19:
48         _BSD_SOURCE || _SVID_SOURCE
49 .fi
50 .SH DESCRIPTION
51 .B Note:
52 avoid using these functions; use
53 .BR mkstemp (3)
55 .BR tmpfile (3)
56 instead.
57 .PP
58 The
59 .BR tmpnam ()
60 function returns a pointer to a string that is a valid filename,
61 and such that a file with this name did not exist at some point
62 in time, so that naive programmers may think it
63 a suitable name for a temporary file.
64 If the argument
65 .I s
66 is NULL, this name is generated in an internal static buffer
67 and may be overwritten by the next call to
68 .BR tmpnam ().
70 .I s
71 is not NULL, the name is copied to the character array (of length
72 at least
73 .IR L_tmpnam )
74 pointed to by
75 .I s
76 and the value
77 .I s
78 is returned in case of success.
79 .PP
80 The created pathname has a directory prefix
81 .IR P_tmpdir .
82 (Both
83 .I L_tmpnam
84 and
85 .I P_tmpdir
86 are defined in
87 .IR <stdio.h> ,
88 just like the
89 .B TMP_MAX
90 mentioned below.)
91 .PP
92 The
93 .BR tmpnam_r ()
94 function performs the same task as
95 .BR tmpnam (),
96 but returns NULL (to indicate an error) if
97 .I s
98 is NULL.
99 .SH RETURN VALUE
100 These functions return a pointer to a unique temporary
101 filename, or NULL if a unique name cannot be generated.
102 .SH ERRORS
103 No errors are defined.
104 .SH ATTRIBUTES
105 For an explanation of the terms used in this section, see
106 .BR attributes (7).
107 .ad l
110 allbox;
111 lbx lb lb
112 l l l.
113 Interface       Attribute       Value
115 .BR tmpnam ()
116 T}      Thread safety   MT-Unsafe race:tmpnam/!s
118 .BR tmpnam_r ()
119 T}      Thread safety   MT-Safe
123 .sp 1
124 .SH CONFORMING TO
125 .BR tmpnam ():
126 SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
127 POSIX.1-2008 marks
128 .BR tmpnam ()
129 as obsolete.
131 .BR tmpnam_r ()
132 is a nonstandard extension that is also available
133 .\" Appears to be on Solaris
134 on a few other systems.
135 .SH NOTES
137 .BR tmpnam ()
138 function generates a different string each time it is called,
139 up to
140 .B TMP_MAX
141 times.
142 If it is called more than
143 .B TMP_MAX
144 times,
145 the behavior is implementation defined.
147 Although these functions generate names that are difficult to guess,
148 it is nevertheless possible that between the time that
149 the pathname is returned and the time that the program opens it,
150 another program might create that pathname using
151 .BR open (2),
152 or create it as a symbolic link.
153 This can lead to security holes.
154 To avoid such possibilities, use the
155 .BR open (2)
156 .B O_EXCL
157 flag to open the pathname.
158 Or better yet, use
159 .BR mkstemp (3)
161 .BR tmpfile (3).
163 Portable applications that use threads cannot call
164 .BR tmpnam ()
165 with a NULL argument if either
166 .B _POSIX_THREADS
168 .B _POSIX_THREAD_SAFE_FUNCTIONS
169 is defined.
170 .SH BUGS
171 Never use these functions.
173 .BR mkstemp (3)
175 .BR tmpfile (3)
176 instead.
177 .SH SEE ALSO
178 .BR mkstemp (3),
179 .BR mktemp (3),
180 .BR tempnam (3),
181 .BR tmpfile (3)