]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/tmpnam.3
man*/: ffix (un-bracket tables)
[thirdparty/man-pages.git] / man3 / tmpnam.3
1 '\" t
2 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .\" 2003-11-15, aeb, added tmpnam_r
7 .\"
8 .TH tmpnam 3 (date) "Linux man-pages (unreleased)"
9 .SH NAME
10 tmpnam, tmpnam_r \- create a name for a temporary file
11 .SH LIBRARY
12 Standard C library
13 .RI ( libc ", " \-lc )
14 .SH SYNOPSIS
15 .nf
16 .B #include <stdio.h>
17 .PP
18 .BI "[[deprecated]] char *tmpnam(char *" s );
19 .BI "[[deprecated]] char *tmpnam_r(char *" s );
20 .fi
21 .PP
22 .RS -4
23 Feature Test Macro Requirements for glibc (see
24 .BR feature_test_macros (7)):
25 .RE
26 .PP
27 .BR tmpnam_r ()
28 .nf
29 Since glibc 2.19:
30 _DEFAULT_SOURCE
31 Up to and including glibc 2.19:
32 _BSD_SOURCE || _SVID_SOURCE
33 .fi
34 .SH DESCRIPTION
35 .B Note:
36 avoid using these functions; use
37 .BR mkstemp (3)
38 or
39 .BR tmpfile (3)
40 instead.
41 .PP
42 The
43 .BR tmpnam ()
44 function returns a pointer to a string that is a valid filename,
45 and such that a file with this name did not exist at some point
46 in time, so that naive programmers may think it
47 a suitable name for a temporary file.
48 If the argument
49 .I s
50 is NULL, this name is generated in an internal static buffer
51 and may be overwritten by the next call to
52 .BR tmpnam ().
53 If
54 .I s
55 is not NULL, the name is copied to the character array (of length
56 at least
57 .IR L_tmpnam )
58 pointed to by
59 .I s
60 and the value
61 .I s
62 is returned in case of success.
63 .PP
64 The created pathname has a directory prefix
65 .IR P_tmpdir .
66 (Both
67 .I L_tmpnam
68 and
69 .I P_tmpdir
70 are defined in
71 .IR <stdio.h> ,
72 just like the
73 .B TMP_MAX
74 mentioned below.)
75 .PP
76 The
77 .BR tmpnam_r ()
78 function performs the same task as
79 .BR tmpnam (),
80 but returns NULL (to indicate an error) if
81 .I s
82 is NULL.
83 .SH RETURN VALUE
84 These functions return a pointer to a unique temporary
85 filename, or NULL if a unique name cannot be generated.
86 .SH ERRORS
87 No errors are defined.
88 .SH ATTRIBUTES
89 For an explanation of the terms used in this section, see
90 .BR attributes (7).
91 .TS
92 allbox;
93 lbx lb lb
94 l l l.
95 Interface Attribute Value
96 T{
97 .na
98 .nh
99 .BR tmpnam ()
100 T} Thread safety MT-Unsafe race:tmpnam/!s
101 T{
102 .na
103 .nh
104 .BR tmpnam_r ()
105 T} Thread safety MT-Safe
106 .TE
107 .sp 1
108 .SH STANDARDS
109 .TP
110 .BR tmpnam ()
111 C11, POSIX.1-2008.
112 .TP
113 .BR tmpnam_r ()
114 None.
115 .SH HISTORY
116 .TP
117 .BR tmpnam ()
118 SVr4, 4.3BSD, C89, POSIX.1-2001.
119 Obsolete in POSIX.1-2008.
120 .TP
121 .BR tmpnam_r ()
122 Solaris.
123 .SH NOTES
124 The
125 .BR tmpnam ()
126 function generates a different string each time it is called,
127 up to
128 .B TMP_MAX
129 times.
130 If it is called more than
131 .B TMP_MAX
132 times,
133 the behavior is implementation defined.
134 .PP
135 Although these functions generate names that are difficult to guess,
136 it is nevertheless possible that between the time that
137 the pathname is returned and the time that the program opens it,
138 another program might create that pathname using
139 .BR open (2),
140 or create it as a symbolic link.
141 This can lead to security holes.
142 To avoid such possibilities, use the
143 .BR open (2)
144 .B O_EXCL
145 flag to open the pathname.
146 Or better yet, use
147 .BR mkstemp (3)
148 or
149 .BR tmpfile (3).
150 .PP
151 Portable applications that use threads cannot call
152 .BR tmpnam ()
153 with a NULL argument if either
154 .B _POSIX_THREADS
155 or
156 .B _POSIX_THREAD_SAFE_FUNCTIONS
157 is defined.
158 .SH BUGS
159 Never use these functions.
160 Use
161 .BR mkstemp (3)
162 or
163 .BR tmpfile (3)
164 instead.
165 .SH SEE ALSO
166 .BR mkstemp (3),
167 .BR mktemp (3),
168 .BR tempnam (3),
169 .BR tmpfile (3)