]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/tmpnam.3
mlock.2: tfix
[thirdparty/man-pages.git] / man3 / tmpnam.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
c13182ef 12.\"
fea681da
MK
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.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
24.\"
25.\" 2003-11-15, aeb, added tmpnam_r
26.\"
4b8c67d9 27.TH TMPNAM 3 2017-09-15 "" "Linux Programmer's Manual"
fea681da
MK
28.SH NAME
29tmpnam, tmpnam_r \- create a name for a temporary file
30.SH SYNOPSIS
31.nf
32.B #include <stdio.h>
dbfe9c70 33.PP
fea681da 34.BI "char *tmpnam(char *" s );
02301948 35.BI "char *tmpnam_r(char *" s );
fea681da 36.fi
68e4db0a 37.PP
02301948
MK
38.in -4n
39Feature Test Macro Requirements for glibc (see
40.BR feature_test_macros (7)):
41.in
68e4db0a 42.PP
02301948
MK
43.BR tmpnam_r ()
44.PD 0
45.ad l
46.RS 4
47.TP 4
48Since glibc 2.19:
49_DEFAULT_SOURCE
50.TP
51Up to and including glibc 2.19:
52_BSD_SOURCE || _SVID_SOURCE
53.RE
54.ad
55.PD
fea681da 56.SH DESCRIPTION
fa90334d 57.B Note:
02301948 58avoid using these functions; use
fa90334d
MK
59.BR mkstemp (3)
60or
61.BR tmpfile (3)
62instead.
847e0d88 63.PP
fea681da 64The
63aa9df0 65.BR tmpnam ()
fea681da
MK
66function returns a pointer to a string that is a valid filename,
67and such that a file with this name did not exist at some point
68in time, so that naive programmers may think it
c13182ef
MK
69a suitable name for a temporary file.
70If the argument
fea681da 71.I s
e0268ba0 72is NULL, this name is generated in an internal static buffer
fea681da 73and may be overwritten by the next call to
63aa9df0 74.BR tmpnam ().
fea681da
MK
75If
76.I s
77is not NULL, the name is copied to the character array (of length
78at least
79.IR L_tmpnam )
80pointed to by
81.I s
82and the value
83.I s
84is returned in case of success.
dd3568a1 85.PP
91d5e32f 86The created pathname has a directory prefix
fea681da
MK
87.IR P_tmpdir .
88(Both
89.I L_tmpnam
90and
91.I P_tmpdir
92are defined in
93.IR <stdio.h> ,
097585ed
MK
94just like the
95.B TMP_MAX
96mentioned below.)
847e0d88 97.PP
fea681da 98The
02301948
MK
99.BR tmpnam_r ()
100function performs the same task as
101.BR tmpnam (),
102but returns NULL (to indicate an error) if
103.I s
104is NULL.
105.SH RETURN VALUE
106These functions return a pointer to a unique temporary
fea681da
MK
107filename, or NULL if a unique name cannot be generated.
108.SH ERRORS
109No errors are defined.
70f5f10e 110.SH ATTRIBUTES
117ae581
PH
111For an explanation of the terms used in this section, see
112.BR attributes (7).
113.TS
114allbox;
115lb lb lb
116l l l.
117Interface Attribute Value
118T{
70f5f10e 119.BR tmpnam ()
9718ae80 120T} Thread safety MT-Unsafe race:tmpnam/!s
117ae581 121T{
70f5f10e 122.BR tmpnam_r ()
117ae581
PH
123T} Thread safety MT-Safe
124.TE
47297adb 125.SH CONFORMING TO
02301948 126.BR tmpnam ():
2b2581ee 127SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
23fc8f53
MK
128POSIX.1-2008 marks
129.BR tmpnam ()
130as obsolete.
847e0d88 131.PP
02301948
MK
132.BR tmpnam_r ()
133is a nonstandard extension that is also available
134.\" Appears to be on Solaris
135on a few other systems.
fea681da
MK
136.SH NOTES
137The
63aa9df0 138.BR tmpnam ()
fea681da 139function generates a different string each time it is called,
097585ed
MK
140up to
141.B TMP_MAX
142times.
143If it is called more than
144.B TMP_MAX
145times,
d9bfdb9c 146the behavior is implementation defined.
dd3568a1 147.PP
02301948 148Although these functions generate names that are difficult to guess,
3b6b5e8b 149it is nevertheless possible that between the time that
02301948 150the pathname is returned and the time that the program opens it,
3b6b5e8b 151another program might create that pathname using
c13182ef 152.BR open (2),
3b6b5e8b
MK
153or create it as a symbolic link.
154This can lead to security holes.
c13182ef 155To avoid such possibilities, use the
3b6b5e8b
MK
156.BR open (2)
157.B O_EXCL
c13182ef
MK
158flag to open the pathname.
159Or better yet, use
3b6b5e8b
MK
160.BR mkstemp (3)
161or
162.BR tmpfile (3).
dd3568a1 163.PP
fea681da 164Portable applications that use threads cannot call
63aa9df0 165.BR tmpnam ()
c4bb193f 166with a NULL argument if either
8c4f34f8
MK
167.B _POSIX_THREADS
168or
169.B _POSIX_THREAD_SAFE_FUNCTIONS
170is defined.
fea681da 171.SH BUGS
02301948 172Never use these functions.
c13182ef 173Use
fea681da 174.BR mkstemp (3)
3b6b5e8b
MK
175or
176.BR tmpfile (3)
fea681da 177instead.
47297adb 178.SH SEE ALSO
fea681da
MK
179.BR mkstemp (3),
180.BR mktemp (3),
181.BR tempnam (3),
182.BR tmpfile (3)