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(): _BSD_SOURCE || _SVID_SOURCE
16

DESCRIPTION

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

RETURN VALUE

43       On  succes, the tempnam() function returns a pointer to a unique tempo‐
44       rary filename.  It returns NULL if a unique name cannot  be  generated,
45       with errno set to indicate the cause of the error.
46

ERRORS

48       ENOMEM Allocation of storage failed.
49

CONFORMING TO

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

NOTES

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

BUGS

79       The  precise  meaning  of "appropriate" is undefined; it is unspecified
80       how accessibility of a directory is determined.
81
82       Never use this function.  Use mkstemp(3) or tmpfile(3) instead.
83

SEE ALSO

85       mkstemp(3), mktemp(3), tmpfile(3), tmpnam(3)
86

COLOPHON

88       This page is part of release 3.53 of the Linux  man-pages  project.   A
89       description  of  the project, and information about reporting bugs, can
90       be found at http://www.kernel.org/doc/man-pages/.
91
92
93
94                                  2013-04-19                        TEMPNAM(3)
Impressum