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

NAME

6       mktemp - make a unique temporary filename
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

43       EINVAL The last six characters of template were not XXXXXX.
44

ATTRIBUTES

46       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
47       tributes(7).
48
49       ┌────────────────────────────────────────────┬───────────────┬─────────┐
50Interface                                   Attribute     Value   
51       ├────────────────────────────────────────────┼───────────────┼─────────┤
52mktemp()                                    │ Thread safety │ MT-Safe │
53       └────────────────────────────────────────────┴───────────────┴─────────┘
54

STANDARDS

56       None.
57

HISTORY

59       4.3BSD, POSIX.1-2001.  Removed in POSIX.1-2008.
60

BUGS

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 test‐
66       ing whether the name exists and opening the file, every use of mktemp()
67       is a security risk.  The race is avoided by mkstemp(3) and mkdtemp(3).
68

SEE ALSO

70       mktemp(1), mkdtemp(3), mkstemp(3), tempnam(3), tmpfile(3), tmpnam(3)
71
72
73
74Linux man-pages 6.04              2023-03-30                         mktemp(3)
Impressum