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       char *tmpnam_r(char *s);
13
14   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16       tmpnam_r()
17           Since glibc 2.19:
18               _DEFAULT_SOURCE
19           Up to and including glibc 2.19:
20               _BSD_SOURCE || _SVID_SOURCE
21

DESCRIPTION

23       Note:  avoid  using  these  functions;  use  mkstemp(3)  or  tmpfile(3)
24       instead.
25
26       The tmpnam() function returns a pointer to a string  that  is  a  valid
27       filename,  and  such  that  a file with this name did not exist at some
28       point in time, so that naive programmers may think it a  suitable  name
29       for  a  temporary file.  If the argument s is NULL, this name is gener‐
30       ated in an internal static buffer and may be overwritten  by  the  next
31       call  to tmpnam().  If s is not NULL, the name is copied to the charac‐
32       ter array (of length at least L_tmpnam) pointed to by s and the value s
33       is returned in case of success.
34
35       The  created  pathname has a directory prefix P_tmpdir.  (Both L_tmpnam
36       and P_tmpdir are defined in <stdio.h>, just like the TMP_MAX  mentioned
37       below.)
38
39       The tmpnam_r() function performs the same task as tmpnam(), but returns
40       NULL (to indicate an error) if s is NULL.
41

RETURN VALUE

43       These functions return a pointer to a  unique  temporary  filename,  or
44       NULL if a unique name cannot be generated.
45

ERRORS

47       No errors are defined.
48

ATTRIBUTES

50       For   an   explanation   of   the  terms  used  in  this  section,  see
51       attributes(7).
52
53       ┌───────────┬───────────────┬──────────────────────────┐
54Interface  Attribute     Value                    
55       ├───────────┼───────────────┼──────────────────────────┤
56tmpnam()   │ Thread safety │ MT-Unsafe race:tmpnam/!s │
57       ├───────────┼───────────────┼──────────────────────────┤
58tmpnam_r() │ Thread safety │ MT-Safe                  │
59       └───────────┴───────────────┴──────────────────────────┘

CONFORMING TO

61       tmpnam(): SVr4, 4.3BSD, C89,  C99,  POSIX.1-2001.   POSIX.1-2008  marks
62       tmpnam() as obsolete.
63
64       tmpnam_r()  is  a nonstandard extension that is also available on a few
65       other systems.
66

NOTES

68       The tmpnam() function generates a different  string  each  time  it  is
69       called,  up to TMP_MAX times.  If it is called more than TMP_MAX times,
70       the behavior is implementation defined.
71
72       Although these functions generate names that are difficult to guess, it
73       is  nevertheless  possible  that  between the time that the pathname is
74       returned and the time that the program opens it, another program  might
75       create  that  pathname  using open(2), or create it as a symbolic link.
76       This can lead to security holes.  To avoid such possibilities, use  the
77       open(2)  O_EXCL  flag  to  open  the  pathname.   Or  better  yet,  use
78       mkstemp(3) or tmpfile(3).
79
80       Portable applications that use threads cannot call tmpnam() with a NULL
81       argument  if  either  _POSIX_THREADS or _POSIX_THREAD_SAFE_FUNCTIONS is
82       defined.
83

BUGS

85       Never use these functions.  Use mkstemp(3) or tmpfile(3) instead.
86

SEE ALSO

88       mkstemp(3), mktemp(3), tempnam(3), tmpfile(3)
89

COLOPHON

91       This page is part of release 5.02 of the Linux  man-pages  project.   A
92       description  of  the project, information about reporting bugs, and the
93       latest    version    of    this    page,    can     be     found     at
94       https://www.kernel.org/doc/man-pages/.
95
96
97
98                                  2017-09-15                         TMPNAM(3)
Impressum