share/mk/: Remove unused variable
[man-pages.git] / man3 / tmpnam.3
blob77ca78d90d2d958cd89137daff7591db2c36eb29
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>
18 .BI "[[deprecated]] char *tmpnam(char *" s );
19 .BI "[[deprecated]] char *tmpnam_r(char *" s );
20 .fi
22 .RS -4
23 Feature Test Macro Requirements for glibc (see
24 .BR feature_test_macros (7)):
25 .RE
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)
39 .BR tmpfile (3)
40 instead.
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 ().
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.
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.)
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
97 .na
98 .nh
99 .BR tmpnam ()
100 T}      Thread safety   MT-Unsafe race:tmpnam/!s
104 .BR tmpnam_r ()
105 T}      Thread safety   MT-Safe
107 .SH STANDARDS
109 .BR tmpnam ()
110 C11, POSIX.1-2008.
112 .BR tmpnam_r ()
113 None.
114 .SH HISTORY
116 .BR tmpnam ()
117 SVr4, 4.3BSD, C89, POSIX.1-2001.
118 Obsolete in POSIX.1-2008.
120 .BR tmpnam_r ()
121 Solaris.
122 .SH NOTES
124 .BR tmpnam ()
125 function generates a different string each time it is called,
126 up to
127 .B TMP_MAX
128 times.
129 If it is called more than
130 .B TMP_MAX
131 times,
132 the behavior is implementation defined.
134 Although these functions generate names that are difficult to guess,
135 it is nevertheless possible that between the time that
136 the pathname is returned and the time that the program opens it,
137 another program might create that pathname using
138 .BR open (2),
139 or create it as a symbolic link.
140 This can lead to security holes.
141 To avoid such possibilities, use the
142 .BR open (2)
143 .B O_EXCL
144 flag to open the pathname.
145 Or better yet, use
146 .BR mkstemp (3)
148 .BR tmpfile (3).
150 Portable applications that use threads cannot call
151 .BR tmpnam ()
152 with a NULL argument if either
153 .B _POSIX_THREADS
155 .B _POSIX_THREAD_SAFE_FUNCTIONS
156 is defined.
157 .SH BUGS
158 Never use these functions.
160 .BR mkstemp (3)
162 .BR tmpfile (3)
163 instead.
164 .SH SEE ALSO
165 .BR mkstemp (3),
166 .BR mktemp (3),
167 .BR tempnam (3),
168 .BR tmpfile (3)