1 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH TEMPNAM 3 2017-09-15 "" "Linux Programmer's Manual"
27 tempnam \- create a name for a temporary file
32 .BI "char *tempnam(const char *" dir ", const char *" pfx );
36 Feature Test Macro Requirements for glibc (see
37 .BR feature_test_macros (7)):
43 Glibc 2.19 and earlier:
44 _BSD_SOURCE || _SVID_SOURCE
46 .I "Never use this function."
55 function returns a pointer to a string that is a valid filename,
56 and such that a file with this name did not exist when
59 The filename suffix of the pathname generated will start with
63 is a non-NULL string of at most five bytes.
64 The directory prefix part of the pathname generated is required to
65 be "appropriate" (often that at least implies writable).
67 Attempts to find an appropriate directory go through the following
71 In case the environment variable
74 contains the name of an appropriate directory, that is used.
79 argument is non-NULL and appropriate, it is used.
86 is used when appropriate.
89 Finally an implementation-defined directory may be used.
91 The string returned by
95 and hence should be freed by
100 function returns a pointer to a unique temporary filename.
101 It returns NULL if a unique name cannot be generated, with
103 set to indicate the cause of the error.
107 Allocation of storage failed.
109 For an explanation of the terms used in this section, see
115 Interface Attribute Value
118 T} Thread safety MT-Safe env
121 SVr4, 4.3BSD, POSIX.1-2001.
128 generates names that are difficult to guess,
129 it is nevertheless possible that between the time that
131 returns a pathname, and the time that the program opens it,
132 another program might create that pathname using
134 or create it as a symbolic link.
135 This can lead to security holes.
136 To avoid such possibilities, use the
139 flag to open the pathname.
145 SUSv2 does not mention the use of
147 glibc will use it only
148 when the program is not set-user-ID.
149 On SVr4, the directory used under \fBd)\fP is
151 (and this is what glibc does).
153 Because it dynamically allocates memory used to return the pathname,
155 is reentrant, and thus thread safe, unlike
160 function generates a different string each time it is called,
166 If it is called more than
169 the behavior is implementation defined.
172 uses at most the first five bytes from
175 The glibc implementation of
179 upon failure to find a unique name.
181 The precise meaning of "appropriate" is undefined;
182 it is unspecified how accessibility of a directory is determined.