1 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH TEMPNAM 3 2021-03-22 "" "Linux Programmer's Manual"
7 tempnam \- create a name for a temporary file
10 .RI ( libc ", " \-lc )
15 .BI "char *tempnam(const char *" dir ", const char *" pfx );
19 Feature Test Macro Requirements for glibc (see
20 .BR feature_test_macros (7)):
27 Glibc 2.19 and earlier:
28 _BSD_SOURCE || _SVID_SOURCE
31 .I "Never use this function."
40 function returns a pointer to a string that is a valid filename,
41 and such that a file with this name did not exist when
44 The filename suffix of the pathname generated will start with
48 is a non-NULL string of at most five bytes.
49 The directory prefix part of the pathname generated is required to
50 be "appropriate" (often that at least implies writable).
52 Attempts to find an appropriate directory go through the following
56 In case the environment variable
59 contains the name of an appropriate directory, that is used.
64 argument is non-NULL and appropriate, it is used.
71 is used when appropriate.
74 Finally an implementation-defined directory may be used.
76 The string returned by
80 and hence should be freed by
85 function returns a pointer to a unique temporary filename.
86 It returns NULL if a unique name cannot be generated, with
88 set to indicate the error.
92 Allocation of storage failed.
94 For an explanation of the terms used in this section, see
102 Interface Attribute Value
105 T} Thread safety MT-Safe env
111 SVr4, 4.3BSD, POSIX.1-2001.
118 generates names that are difficult to guess,
119 it is nevertheless possible that between the time that
121 returns a pathname, and the time that the program opens it,
122 another program might create that pathname using
124 or create it as a symbolic link.
125 This can lead to security holes.
126 To avoid such possibilities, use the
129 flag to open the pathname.
135 SUSv2 does not mention the use of
137 glibc will use it only
138 when the program is not set-user-ID.
139 On SVr4, the directory used under \fBd)\fP is
141 (and this is what glibc does).
143 Because it dynamically allocates memory used to return the pathname,
145 is reentrant, and thus thread safe, unlike
150 function generates a different string each time it is called,
156 If it is called more than
159 the behavior is implementation defined.
162 uses at most the first five bytes from
165 The glibc implementation of
169 upon failure to find a unique name.
171 The precise meaning of "appropriate" is undefined;
172 it is unspecified how accessibility of a directory is determined.