Debian Codegraph @

upstream/debian-trixie/man3/mktemp.3

raw
1 '\" t
2 .\" Copyright (C) 1993 David Metcalfe ([email protected])
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .\" References consulted:
7 .\" Linux libc source code
8 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
9 .\" 386BSD man pages
10 .\" Modified Sat Jul 24 18:48:06 1993 by Rik Faith ([email protected])
11 .\" Modified Fri Jun 23 01:26:34 1995 by Andries Brouwer ([email protected])
12 .\" (prompted by Scott Burkett <[email protected]>)
13 .\" Modified Sun Mar 28 23:44:38 1999 by Andries Brouwer ([email protected])
14 .\"
15 .TH mktemp 3 2024-05-02 "Linux man-pages 6.9.1"
16 .SH NAME
17 mktemp \- make a unique temporary filename
18 .SH LIBRARY
19 Standard C library
20 .RI ( libc ", " \-lc )
21 .SH SYNOPSIS
22 .nf
23 .B #include <stdlib.h>
24 .P
25 .BI "char *mktemp(char *" template );
26 .fi
27 .P
28 .RS -4
29 Feature Test Macro Requirements for glibc (see
30 .BR feature_test_macros (7)):
31 .RE
32 .P
33 .BR mktemp ():
34 .nf
35 Since glibc 2.12:
36 (_XOPEN_SOURCE >= 500) && ! (_POSIX_C_SOURCE >= 200112L)
37 || /* glibc >= 2.19: */ _DEFAULT_SOURCE
38 || /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
39 Before glibc 2.12:
40 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500
41 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
42 .fi
43 .SH DESCRIPTION
44 .IR "Never use this function" ;
45 see BUGS.
46 .P
47 The
48 .BR mktemp ()
49 function generates a unique temporary filename
50 from \fItemplate\fP.
51 The last six characters of \fItemplate\fP must
52 be XXXXXX and these are replaced with a string that makes the
53 filename unique.
54 Since it will be modified,
55 .I template
56 must not be a string constant, but should be declared as a character array.
57 .SH RETURN VALUE
58 The
59 .BR mktemp ()
60 function always returns \fItemplate\fP.
61 If a unique name was created, the last six bytes of \fItemplate\fP will
62 have been modified in such a way that the resulting name is unique
63 (i.e., does not exist already)
64 If a unique name could not be created,
65 \fItemplate\fP is made an empty string, and
66 .I errno
67 is set to indicate the error.
68 .SH ERRORS
69 .TP
70 .B EINVAL
71 The last six characters of \fItemplate\fP were not XXXXXX.
72 .SH ATTRIBUTES
73 For an explanation of the terms used in this section, see
74 .BR attributes (7).
75 .TS
76 allbox;
77 lbx lb lb
78 l l l.
79 Interface Attribute Value
80 T{
81 .na
82 .nh
83 .BR mktemp ()
84 T} Thread safety MT-Safe
85 .TE
86 .SH STANDARDS
87 None.
88 .SH HISTORY
89 4.3BSD, POSIX.1-2001.
90 Removed in POSIX.1-2008.
91 .\" .SH NOTES
92 .\" The prototype is in
93 .\" .I <unistd.h>
94 .\" for libc4, libc5, glibc1; glibc2 follows the Single UNIX Specification
95 .\" and has the prototype in
96 .\" .IR <stdlib.h> .
97 .SH BUGS
98 Never use
99 .BR mktemp ().
100 Some implementations follow 4.3BSD
101 and replace XXXXXX by the current process ID and a single letter,
102 so that at most 26 different names can be returned.
103 Since on the one hand the names are easy to guess, and on the other
104 hand there is a race between testing whether the name exists and
105 opening the file, every use of
106 .BR mktemp ()
107 is a security risk.
108 The race is avoided by
109 .BR mkstemp (3)
110 and
111 .BR mkdtemp (3).
112 .SH SEE ALSO
113 .BR mktemp (1),
114 .BR mkdtemp (3),
115 .BR mkstemp (3),
116 .BR tempnam (3),
117 .BR tmpfile (3),
118 .BR tmpnam (3)