]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/tmpnam.3
membarrier.2: Remove redundant mention of return value of MEMBARRIER_CMD_SHARED
[thirdparty/man-pages.git] / man3 / tmpnam.3
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 2015-03-02 "" "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 .sp
34 .BI "char *tmpnam(char *" s );
35 .fi
36 .SH DESCRIPTION
37 .B Note:
38 Avoid use of
39 .BR tmpnam ();
40 use
41 .BR mkstemp (3)
42 or
43 .BR tmpfile (3)
44 instead.
45
46 The
47 .BR tmpnam ()
48 function returns a pointer to a string that is a valid filename,
49 and such that a file with this name did not exist at some point
50 in time, so that naive programmers may think it
51 a suitable name for a temporary file.
52 If the argument
53 .I s
54 is NULL, this name is generated in an internal static buffer
55 and may be overwritten by the next call to
56 .BR tmpnam ().
57 If
58 .I s
59 is not NULL, the name is copied to the character array (of length
60 at least
61 .IR L_tmpnam )
62 pointed to by
63 .I s
64 and the value
65 .I s
66 is returned in case of success.
67 .LP
68 The pathname that is created, has a directory prefix
69 .IR P_tmpdir .
70 (Both
71 .I L_tmpnam
72 and
73 .I P_tmpdir
74 are defined in
75 .IR <stdio.h> ,
76 just like the
77 .B TMP_MAX
78 mentioned below.)
79 .SH RETURN VALUE
80 The
81 .BR tmpnam ()
82 function returns a pointer to a unique temporary
83 filename, or NULL if a unique name cannot be generated.
84 .SH ERRORS
85 No errors are defined.
86 .SH ATTRIBUTES
87 For an explanation of the terms used in this section, see
88 .BR attributes (7).
89 .TS
90 allbox;
91 lb lb lb
92 l l l.
93 Interface Attribute Value
94 T{
95 .BR tmpnam ()
96 T} Thread safety MT-Unsafe race:tmpnam/!s
97 T{
98 .BR tmpnam_r ()
99 T} Thread safety MT-Safe
100 .TE
101 .SH CONFORMING TO
102 SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
103 POSIX.1-2008 marks
104 .BR tmpnam ()
105 as obsolete.
106 .SH NOTES
107 The
108 .BR tmpnam ()
109 function generates a different string each time it is called,
110 up to
111 .B TMP_MAX
112 times.
113 If it is called more than
114 .B TMP_MAX
115 times,
116 the behavior is implementation defined.
117 .LP
118 Although
119 .BR tmpnam ()
120 generates names that are difficult to guess,
121 it is nevertheless possible that between the time that
122 .BR tmpnam ()
123 returns a pathname, and the time that the program opens it,
124 another program might create that pathname using
125 .BR open (2),
126 or create it as a symbolic link.
127 This can lead to security holes.
128 To avoid such possibilities, use the
129 .BR open (2)
130 .B O_EXCL
131 flag to open the pathname.
132 Or better yet, use
133 .BR mkstemp (3)
134 or
135 .BR tmpfile (3).
136 .LP
137 Portable applications that use threads cannot call
138 .BR tmpnam ()
139 with a NULL argument if either
140 .B _POSIX_THREADS
141 or
142 .B _POSIX_THREAD_SAFE_FUNCTIONS
143 is defined.
144 .LP
145 A POSIX draft proposed to use a function
146 .BR tmpnam_r ()
147 defined by
148 .sp
149 .nf
150 .in +4n
151 char *
152 tmpnam_r(char *s)
153 {
154 return s ? tmpnam(s) : NULL;
155 }
156 .in
157 .fi
158 .sp
159 apparently as a warning not to use NULL.
160 A few systems implement it.
161 To get a glibc prototype for this function from
162 .IR <stdio.h> ,
163 define
164 .B _SVID_SOURCE
165 or
166 .B _BSD_SOURCE
167 (before including
168 .I any
169 header file).
170 .SH BUGS
171 Never use this function.
172 Use
173 .BR mkstemp (3)
174 or
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)