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) in‐
24       stead.
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 at‐
51       tributes(7).
52
53       ┌───────────────────────────┬───────────────┬──────────────────────────┐
54Interface                  Attribute     Value                    
55       ├───────────────────────────┼───────────────┼──────────────────────────┤
56tmpnam()                   │ Thread safety │ MT-Unsafe race:tmpnam/!s │
57       ├───────────────────────────┼───────────────┼──────────────────────────┤
58tmpnam_r()                 │ Thread safety │ MT-Safe                  │
59       └───────────────────────────┴───────────────┴──────────────────────────┘
60

CONFORMING TO

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

NOTES

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

BUGS

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

SEE ALSO

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

COLOPHON

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