]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/mktemp.3
fuse.4: ffix
[thirdparty/man-pages.git] / man3 / mktemp.3
CommitLineData
fea681da
MK
1.\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
7.\"
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.
c13182ef 12.\"
fea681da
MK
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
19.\" professionally.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
24.\"
25.\" References consulted:
26.\" Linux libc source code
27.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28.\" 386BSD man pages
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)
33.\"
4b8c67d9 34.TH MKTEMP 3 2017-09-15 "GNU" "Linux Programmer's Manual"
fea681da 35.SH NAME
2c5f1089 36mktemp \- make a unique temporary filename
fea681da
MK
37.SH SYNOPSIS
38.nf
39.B #include <stdlib.h>
68e4db0a 40.PP
fea681da
MK
41.BI "char *mktemp(char *" template );
42.fi
68e4db0a 43.PP
cc4615cc
MK
44.in -4n
45Feature Test Macro Requirements for glibc (see
46.BR feature_test_macros (7)):
47.in
68e4db0a 48.PP
cc4615cc 49.BR mktemp ():
77ea385c
MK
50.ad l
51.PD 0
1348fbcb 52.RS 4
f660f936 53.TP 4
77ea385c 54Since glibc 2.12:
2b1b0424
MK
55(_XOPEN_SOURCE\ >=\ 500) && ! (_POSIX_C_SOURCE\ >=\ 200112L)
56 || /* Glibc since 2.19: */ _DEFAULT_SOURCE
57 || /* Glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
77ea385c
MK
58.TP
59Before glibc 2.12:
cf7fa0a1
MK
60_BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500
61.\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
b23c187c 62.RE
77ea385c
MK
63.PD
64.ad b
fea681da 65.SH DESCRIPTION
3fd22afa 66.IR "Never use this function" ;
fcf4536c 67see BUGS.
847e0d88 68.PP
60a90ecd
MK
69The
70.BR mktemp ()
71function generates a unique temporary filename
1c44bd5b
MK
72from \fItemplate\fP.
73The last six characters of \fItemplate\fP must
fea681da 74be XXXXXX and these are replaced with a string that makes the
c13182ef
MK
75filename unique.
76Since it will be modified,
fea681da
MK
77.I template
78must not be a string constant, but should be declared as a character array.
47297adb 79.SH RETURN VALUE
60a90ecd
MK
80The
81.BR mktemp ()
d0eb630e
MK
82function always returns \fItemplate\fP.
83If a unique name was created, the last six bytes of \fItemplate\fP will
fea681da 84have been modified in such a way that the resulting name is unique
d0eb630e
MK
85(i.e., does not exist already)
86If a unique name could not be created,
c03c3dd4
MK
87\fItemplate\fP is made an empty string, and
88.I errno
89is set to indicate the error.
fea681da
MK
90.SH ERRORS
91.TP
92.B EINVAL
93The last six characters of \fItemplate\fP were not XXXXXX.
bce660dc
PH
94.SH ATTRIBUTES
95For an explanation of the terms used in this section, see
96.BR attributes (7).
97.TS
98allbox;
99lb lb lb
100l l l.
101Interface Attribute Value
102T{
103.BR mktemp ()
104T} Thread safety MT-Safe
105.TE
47297adb 106.SH CONFORMING TO
fa5e7dd9 1074.3BSD, POSIX.1-2001.
a2fa863a
MK
108POSIX.1-2008 removes the specification of
109.BR mktemp ().
c6baa019
MK
110.\" .SH NOTES
111.\" The prototype is in
112.\" .I <unistd.h>
113.\" for libc4, libc5, glibc1; glibc2 follows the Single UNIX Specification
114.\" and has the prototype in
115.\" .IR <stdlib.h> .
fea681da 116.SH BUGS
60a90ecd
MK
117Never use
118.BR mktemp ().
c13182ef 119Some implementations follow 4.3BSD
357cf3fe 120and replace XXXXXX by the current process ID and a single letter,
fea681da
MK
121so that at most 26 different names can be returned.
122Since on the one hand the names are easy to guess, and on the other
123hand there is a race between testing whether the name exists and
60a90ecd
MK
124opening the file, every use of
125.BR mktemp ()
126is a security risk.
fea681da 127The race is avoided by
d6dcb338
MK
128.BR mkstemp (3)
129and
9b44ad20 130.BR mkdtemp (3).
47297adb 131.SH SEE ALSO
c39946e0 132.BR mktemp (1),
9b44ad20 133.BR mkdtemp (3),
fea681da
MK
134.BR mkstemp (3),
135.BR tempnam (3),
136.BR tmpfile (3),
137.BR tmpnam (3)