2 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH tempnam 3 (date) "Linux man-pages (unreleased)"
8 tempnam \- create a name for a temporary file
11 .RI ( libc ", " \-lc )
16 .BI "char *tempnam(const char *" dir ", const char *" pfx );
20 Feature Test Macro Requirements for glibc (see
21 .BR feature_test_macros (7)):
28 glibc 2.19 and earlier:
29 _BSD_SOURCE || _SVID_SOURCE
32 .I "Never use this function."
41 function returns a pointer to a string that is a valid filename,
42 and such that a file with this name did not exist when
45 The filename suffix of the pathname generated will start with
49 is a non-NULL string of at most five bytes.
50 The directory prefix part of the pathname generated is required to
51 be "appropriate" (often that at least implies writable).
53 Attempts to find an appropriate directory go through the following
57 In case the environment variable
60 contains the name of an appropriate directory, that is used.
65 argument is non-NULL and appropriate, it is used.
72 is used when appropriate.
75 Finally an implementation-defined directory may be used.
77 The string returned by
81 and hence should be freed by
86 function returns a pointer to a unique temporary filename.
87 It returns NULL if a unique name cannot be generated, with
89 set to indicate the error.
93 Allocation of storage failed.
95 For an explanation of the terms used in this section, see
101 Interface Attribute Value
106 T} Thread safety MT-Safe env
111 SVr4, 4.3BSD, POSIX.1-2001.
112 Obsoleted in POSIX.1-2008.
116 generates names that are difficult to guess,
117 it is nevertheless possible that between the time that
119 returns a pathname, and the time that the program opens it,
120 another program might create that pathname using
122 or create it as a symbolic link.
123 This can lead to security holes.
124 To avoid such possibilities, use the
127 flag to open the pathname.
133 SUSv2 does not mention the use of
135 glibc will use it only
136 when the program is not set-user-ID.
137 On SVr4, the directory used under \fBd)\fP is
139 (and this is what glibc does).
141 Because it dynamically allocates memory used to return the pathname,
143 is reentrant, and thus thread safe, unlike
148 function generates a different string each time it is called,
154 If it is called more than
157 the behavior is implementation defined.
160 uses at most the first five bytes from
163 The glibc implementation of
167 upon failure to find a unique name.
169 The precise meaning of "appropriate" is undefined;
170 it is unspecified how accessibility of a directory is determined.