1 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .TH TEMPNAM 3 2008-08-06 "" "Linux Programmer's Manual"
25 tempnam \- create a name for a temporary file
30 .BI "char *tempnam(const char *" dir ", const char *" pfx );
34 Feature Test Macro Requirements for glibc (see
35 .BR feature_test_macros (7)):
39 _BSD_SOURCE || _SVID_SOURCE
43 function returns a pointer to a string that is a valid filename,
44 and such that a file with this name did not exist when
47 The filename suffix of the pathname generated will start with
51 is a non-NULL string of at most five bytes.
52 The directory prefix part of the pathname generated is required to
53 be "appropriate" (often that at least implies writable).
55 Attempts to find an appropriate directory go through the following
59 In case the environment variable
62 contains the name of an appropriate directory, that is used.
67 argument is non-NULL and appropriate, it is used.
74 is used when appropriate.
77 Finally an implementation-defined directory may be used.
79 The string returned by
83 and hence should be freed by
88 function returns a pointer to a unique temporary
89 filename, or NULL if a unique name cannot be generated.
93 Allocation of storage failed.
95 SVr4, 4.3BSD, POSIX.1-2001.
102 generates names that are difficult to guess,
103 it is nevertheless possible that between the time that
105 returns a pathname, and the time that the program opens it,
106 another program might create that pathname using
108 or create it as a symbolic link.
109 This can lead to security holes.
110 To avoid such possibilities, use the
113 flag to open the pathname.
119 SUSv2 does not mention the use of
121 glibc will use it only
122 when the program is not set-user-ID.
123 On SVr4, the directory used under \fBd)\fP is
125 (and this is what glibc does).
127 Because it dynamically allocates memory used to return the pathname,
129 is reentrant, and thus thread safe, unlike
134 function generates a different string each time it is called,
140 If it is called more than
143 the behavior is implementation defined.
146 uses at most the first five bytes from
149 The glibc implementation of
151 will fail with the error
153 upon failure to find a unique name.
155 The precise meaning of "appropriate" is undefined;
156 it is unspecified how accessibility of a directory is determined.
158 Never use this function.