1TEMPNAM(3)                 Linux Programmer's Manual                TEMPNAM(3)
2
3
4

NAME

6       tempnam - create a name for a temporary file
7

SYNOPSIS

9       #include <stdio.h>
10
11       char *tempnam(const char *dir, const char *pfx);
12
13   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
14
15       tempnam():
16           Since glibc 2.19:
17               _DEFAULT_SOURCE
18           Glibc 2.19 and earlier:
19               _BSD_SOURCE || _SVID_SOURCE
20

DESCRIPTION

22       Never use this function.  Use mkstemp(3) or tmpfile(3) instead.
23
24       The  tempnam()  function  returns a pointer to a string that is a valid
25       filename, and such that a file with this name did not exist when  temp‐
26       nam()  checked.   The  filename  suffix  of the pathname generated will
27       start with pfx in case pfx is a non-NULL string of at most five  bytes.
28       The  directory  prefix part of the pathname generated is required to be
29       "appropriate" (often that at least implies writable).
30
31       Attempts to find an appropriate  directory  go  through  the  following
32       steps:
33
34       a) In case the environment variable TMPDIR exists and contains the name
35          of an appropriate directory, that is used.
36
37       b) Otherwise, if the dir argument is non-NULL and  appropriate,  it  is
38          used.
39
40       c) Otherwise, P_tmpdir (as defined in <stdio.h>) is used when appropri‐
41          ate.
42
43       d) Finally an implementation-defined directory may be used.
44
45       The string returned by tempnam() is allocated using malloc(3) and hence
46       should be freed by free(3).
47

RETURN VALUE

49       On success, the tempnam() function returns a pointer to a unique tempo‐
50       rary filename.  It returns NULL if a unique name cannot  be  generated,
51       with errno set to indicate the cause of the error.
52

ERRORS

54       ENOMEM Allocation of storage failed.
55

ATTRIBUTES

57       For   an   explanation   of   the  terms  used  in  this  section,  see
58       attributes(7).
59
60       ┌──────────┬───────────────┬─────────────┐
61Interface Attribute     Value       
62       ├──────────┼───────────────┼─────────────┤
63tempnam() │ Thread safety │ MT-Safe env │
64       └──────────┴───────────────┴─────────────┘

CONFORMING TO

66       SVr4, 4.3BSD, POSIX.1-2001.  POSIX.1-2008 marks tempnam() as obsolete.
67

NOTES

69       Although tempnam() generates names that are difficult to guess,  it  is
70       nevertheless  possible  that  between the time that tempnam() returns a
71       pathname, and the time that the program opens it, another program might
72       create  that  pathname  using open(2), or create it as a symbolic link.
73       This can lead to security holes.  To avoid such possibilities, use  the
74       open(2)  O_EXCL  flag  to  open  the  pathname.   Or  better  yet,  use
75       mkstemp(3) or tmpfile(3).
76
77       SUSv2 does not mention the use of TMPDIR; glibc will use it  only  when
78       the  program  is not set-user-ID.  On SVr4, the directory used under d)
79       is /tmp (and this is what glibc does).
80
81       Because it dynamically allocates memory used to  return  the  pathname,
82       tempnam() is reentrant, and thus thread safe, unlike tmpnam(3).
83
84       The  tempnam()  function  generates  a different string each time it is
85       called, up to TMP_MAX (defined in <stdio.h>) times.  If  it  is  called
86       more than TMP_MAX times, the behavior is implementation defined.
87
88       tempnam() uses at most the first five bytes from pfx.
89
90       The  glibc implementation of tempnam() fails with the error EEXIST upon
91       failure to find a unique name.
92

BUGS

94       The precise meaning of "appropriate" is undefined;  it  is  unspecified
95       how accessibility of a directory is determined.
96

SEE ALSO

98       mkstemp(3), mktemp(3), tmpfile(3), tmpnam(3)
99

COLOPHON

101       This  page  is  part of release 4.15 of the Linux man-pages project.  A
102       description of the project, information about reporting bugs,  and  the
103       latest     version     of     this    page,    can    be    found    at
104       https://www.kernel.org/doc/man-pages/.
105
106
107
108                                  2017-09-15                        TEMPNAM(3)
Impressum