1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" References consulted:
6 .\" Linux libc source code
7 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
9 .\" Modified Sat Jul 24 18:48:06 1993 by Rik Faith (faith@cs.unc.edu)
10 .\" Modified Fri Jun 23 01:26:34 1995 by Andries Brouwer (aeb@cwi.nl)
11 .\" (prompted by Scott Burkett <scottb@IntNet.net>)
12 .\" Modified Sun Mar 28 23:44:38 1999 by Andries Brouwer (aeb@cwi.nl)
14 .TH MKTEMP 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
16 mktemp \- make a unique temporary filename
19 .RI ( libc ", " \-lc )
22 .B #include <stdlib.h>
24 .BI "char *mktemp(char *" template );
28 Feature Test Macro Requirements for glibc (see
29 .BR feature_test_macros (7)):
35 (_XOPEN_SOURCE >= 500) && ! (_POSIX_C_SOURCE >= 200112L)
36 || /* Glibc since 2.19: */ _DEFAULT_SOURCE
37 || /* Glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
39 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500
40 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
43 .IR "Never use this function" ;
48 function generates a unique temporary filename
50 The last six characters of \fItemplate\fP must
51 be XXXXXX and these are replaced with a string that makes the
53 Since it will be modified,
55 must not be a string constant, but should be declared as a character array.
59 function always returns \fItemplate\fP.
60 If a unique name was created, the last six bytes of \fItemplate\fP will
61 have been modified in such a way that the resulting name is unique
62 (i.e., does not exist already)
63 If a unique name could not be created,
64 \fItemplate\fP is made an empty string, and
66 is set to indicate the error.
70 The last six characters of \fItemplate\fP were not XXXXXX.
72 For an explanation of the terms used in this section, see
80 Interface Attribute Value
83 T} Thread safety MT-Safe
90 POSIX.1-2008 removes the specification of
93 .\" The prototype is in
95 .\" for libc4, libc5, glibc1; glibc2 follows the Single UNIX Specification
96 .\" and has the prototype in
101 Some implementations follow 4.3BSD
102 and replace XXXXXX by the current process ID and a single letter,
103 so that at most 26 different names can be returned.
104 Since on the one hand the names are easy to guess, and on the other
105 hand there is a race between testing whether the name exists and
106 opening the file, every use of
109 The race is avoided by