1tmpnam(3)                  Library Functions Manual                  tmpnam(3)
2
3
4

NAME

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

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <stdio.h>
13
14       [[deprecated]] char *tmpnam(char *s);
15       [[deprecated]] char *tmpnam_r(char *s);
16
17   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19       tmpnam_r()
20           Since glibc 2.19:
21               _DEFAULT_SOURCE
22           Up to and including glibc 2.19:
23               _BSD_SOURCE || _SVID_SOURCE
24

DESCRIPTION

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

RETURN VALUE

46       These functions return a pointer to a  unique  temporary  filename,  or
47       NULL if a unique name cannot be generated.
48

ERRORS

50       No errors are defined.
51

ATTRIBUTES

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

STANDARDS

65       tmpnam()
66              C11, POSIX.1-2008.
67
68       tmpnam_r()
69              None.
70

HISTORY

72       tmpnam()
73              SVr4, 4.3BSD, C89, POSIX.1-2001.  Obsolete in POSIX.1-2008.
74
75       tmpnam_r()
76              Solaris.
77

NOTES

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

BUGS

96       Never use these functions.  Use mkstemp(3) or tmpfile(3) instead.
97

SEE ALSO

99       mkstemp(3), mktemp(3), tempnam(3), tmpfile(3)
100
101
102
103Linux man-pages 6.04              2023-03-30                         tmpnam(3)
Impressum