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

NAME

6       tmpnam, tmpnam_r - create a name for a temporary file
7

SYNOPSIS

9       #include <stdio.h>
10
11       char *tmpnam(char *s);
12

DESCRIPTION

14       The  tmpnam()  function  returns  a pointer to a string that is a valid
15       filename, and such that a file with this name did  not  exist  at  some
16       point  in  time, so that naive programmers may think it a suitable name
17       for a temporary file.  If the argument s is NULL this name is generated
18       in an internal static buffer and may be overwritten by the next call to
19       tmpnam().  If s is not NULL, the name is copied to the character  array
20       (of  length  at  least  L_tmpnam)  pointed  to  by s and the value s is
21       returned in case of success.
22
23       The pathname that is created, has a directory prefix  P_tmpdir.   (Both
24       L_tmpnam  and  P_tmpdir are defined in <stdio.h>, just like the TMP_MAX
25       mentioned below.)
26

RETURN VALUE

28       The tmpnam() function returns a pointer to a unique temporary filename,
29       or NULL if a unique name cannot be generated.
30

ERRORS

32       No errors are defined.
33

ATTRIBUTES

35   Multithreading (see pthreads(7))
36       The  tmpnam()  function  is  thread-safe  with  exceptions.   It is not
37       thread-safe if called with a NULL parameter.
38
39       The tmpnam_r() function is thread-safe.
40

CONFORMING TO

42       SVr4, 4.3BSD, C89, C99, POSIX.1-2001.  POSIX.1-2008 marks  tmpnam()  as
43       obsolete.
44

NOTES

46       The  tmpnam()  function  generates  a  different string each time it is
47       called, up to TMP_MAX times.  If it is called more than TMP_MAX  times,
48       the behavior is implementation defined.
49
50       Although  tmpnam()  generates  names that are difficult to guess, it is
51       nevertheless possible that between the time  that  tmpnam()  returns  a
52       pathname, and the time that the program opens it, another program might
53       create that pathname using open(2), or create it as  a  symbolic  link.
54       This  can lead to security holes.  To avoid such possibilities, use the
55       open(2)  O_EXCL  flag  to  open  the  pathname.   Or  better  yet,  use
56       mkstemp(3) or tmpfile(3).
57
58       Portable applications that use threads cannot call tmpnam() with a NULL
59       argument if either _POSIX_THREADS  or  _POSIX_THREAD_SAFE_FUNCTIONS  is
60       defined.
61
62       A POSIX draft proposed to use a function tmpnam_r() defined by
63
64           char *
65           tmpnam_r(char *s)
66           {
67               return s ? tmpnam(s) : NULL;
68           }
69
70       apparently  as  a warning not to use NULL.  A few systems implement it.
71       To get a glibc prototype  for  this  function  from  <stdio.h>,  define
72       _SVID_SOURCE or _BSD_SOURCE (before including any header file).
73

BUGS

75       Never use this function.  Use mkstemp(3) or tmpfile(3) instead.
76

SEE ALSO

78       mkstemp(3), mktemp(3), tempnam(3), tmpfile(3)
79

COLOPHON

81       This  page  is  part of release 3.53 of the Linux man-pages project.  A
82       description of the project, and information about reporting  bugs,  can
83       be found at http://www.kernel.org/doc/man-pages/.
84
85
86
87                                  2013-06-21                         TMPNAM(3)
Impressum