1mktemp(3) Library Functions Manual mktemp(3)
2
3
4
6 mktemp - make a unique temporary filename
7
9 Standard C library (libc, -lc)
10
12 #include <stdlib.h>
13
14 char *mktemp(char *template);
15
16 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
17
18 mktemp():
19 Since glibc 2.12:
20 (_XOPEN_SOURCE >= 500) && ! (_POSIX_C_SOURCE >= 200112L)
21 || /* glibc >= 2.19: */ _DEFAULT_SOURCE
22 || /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
23 Before glibc 2.12:
24 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500
25
27 Never use this function; see BUGS.
28
29 The mktemp() function generates a unique temporary filename from tem‐
30 plate. The last six characters of template must be XXXXXX and these
31 are replaced with a string that makes the filename unique. Since it
32 will be modified, template must not be a string constant, but should be
33 declared as a character array.
34
36 The mktemp() function always returns template. If a unique name was
37 created, the last six bytes of template will have been modified in such
38 a way that the resulting name is unique (i.e., does not exist already)
39 If a unique name could not be created, template is made an empty
40 string, and errno is set to indicate the error.
41
43 EINVAL The last six characters of template were not XXXXXX.
44
46 For an explanation of the terms used in this section, see at‐
47 tributes(7).
48
49 ┌────────────────────────────────────────────┬───────────────┬─────────┐
50 │Interface │ Attribute │ Value │
51 ├────────────────────────────────────────────┼───────────────┼─────────┤
52 │mktemp() │ Thread safety │ MT-Safe │
53 └────────────────────────────────────────────┴───────────────┴─────────┘
54
56 None.
57
59 4.3BSD, POSIX.1-2001. Removed in POSIX.1-2008.
60
62 Never use mktemp(). Some implementations follow 4.3BSD and replace
63 XXXXXX by the current process ID and a single letter, so that at most
64 26 different names can be returned. Since on the one hand the names
65 are easy to guess, and on the other hand there is a race between
66 testing whether the name exists and opening the file, every use of
67 mktemp() is a security risk. The race is avoided by mkstemp(3) and
68 mkdtemp(3).
69
71 mktemp(1), mkdtemp(3), mkstemp(3), tempnam(3), tmpfile(3), tmpnam(3)
72
73
74
75Linux man-pages 6.05 2023-07-20 mktemp(3)