1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" References consulted:
26 .\" Linux libc source code
27 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
29 .\" Modified Sat Jul 24 18:48:06 1993 by Rik Faith (faith@cs.unc.edu)
30 .\" Modified Fri Jun 23 01:26:34 1995 by Andries Brouwer (aeb@cwi.nl)
31 .\" (prompted by Scott Burkett <scottb@IntNet.net>)
32 .\" Modified Sun Mar 28 23:44:38 1999 by Andries Brouwer (aeb@cwi.nl)
34 .TH MKTEMP 3 2014-08-19 "GNU" "Linux Programmer's Manual"
36 mktemp \- make a unique temporary filename
39 .B #include <stdlib.h>
41 .BI "char *mktemp(char *" template );
45 Feature Test Macro Requirements for glibc (see
46 .BR feature_test_macros (7)):
55 _BSD_SOURCE || _SVID_SOURCE ||
56 (_XOPEN_SOURCE\ >=\ 500 ||
57 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
58 !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
61 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
62 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
67 .IR "Never use this function" ;
72 function generates a unique temporary filename
74 The last six characters of \fItemplate\fP must
75 be XXXXXX and these are replaced with a string that makes the
77 Since it will be modified,
79 must not be a string constant, but should be declared as a character array.
83 function always returns \fItemplate\fP.
84 If a unique name was created, the last six bytes of \fItemplate\fP will
85 have been modified in such a way that the resulting name is unique
86 (i.e., does not exist already)
87 If a unique name could not be created,
88 \fItemplate\fP is made an empty string, and
90 is set to indicate the error.
94 The last six characters of \fItemplate\fP were not XXXXXX.
97 POSIX.1-2008 removes the specification of
100 .\" The prototype is in
102 .\" for libc4, libc5, glibc1; glibc2 follows the Single UNIX Specification
103 .\" and has the prototype in
108 Some implementations follow 4.3BSD
109 and replace XXXXXX by the current process ID and a single letter,
110 so that at most 26 different names can be returned.
111 Since on the one hand the names are easy to guess, and on the other
112 hand there is a race between testing whether the name exists and
113 opening the file, every use of
116 The race is avoided by