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 1999-06-14 "" "Linux Programmer's Manual"
25 tempnam \- create a name for a temporary file
30 .BI "char *tempnam(const char *" dir ", const char *" pfx );
35 function returns a pointer to a string that is a valid filename,
36 and such that a file with this name did not exist when
39 The filename suffix of the pathname generated will start with
43 is a non-NULL string of at most five bytes.
44 The directory prefix part of the pathname generated is required to
45 be `appropriate' (often that at least implies writable).
47 Attempts to find an appropriate directory go through the following
51 In case the environment variable TMPDIR exists and
52 contains the name of an appropriate directory, that is used.
57 argument is non-NULL and appropriate, it is used.
64 is used when appropriate.
67 Finally an implementation-defined directory may be used.
69 The string returned by
73 and hence should be freed by
78 function returns a pointer to a unique temporary
79 filename, or NULL if a unique name cannot be generated.
83 Allocation of storage failed.
85 SVr4, 4.3BSD, POSIX.1-2001
89 generates names that are difficult to guess,
90 it is nevertheless possible that between the time that
92 returns a pathname, and the time that the program opens it,
93 another program might create that pathname using
95 or create it as a symbolic link.
96 This can lead to security holes.
97 To avoid such possibilities, use the
100 flag to open the pathname.
106 SUSv2 does not mention the use of TMPDIR; glibc will use it only
107 when the program is not set-user-ID.
108 On SVr4, the directory used under \fBd)\fP is
110 (and this is what glibc does).
112 Because it dynamically allocates memory used to return the pathname,
114 is reentrant, and thus thread safe, unlike
119 function generates a different string each time it is called,
120 up to TMP_MAX (defined in
123 If it is called more than TMP_MAX times,
124 the behaviour is implementation defined.
127 uses at most the first five bytes from
130 The glibc implementation of
132 will fail with the error
134 upon failure to find a unique name.
136 The precise meaning of `appropriate' is undefined;
137 it is unspecified how accessibility of a directory is determined.
139 Never use this function.