OSDN Git Service

(split) LDP: Update original to LDP v3.50.
[linuxjm/LDP_man-pages.git] / original / man3 / mktemp.3
1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
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.
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.
12 .\"
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.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
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 .\"
34 .TH MKTEMP 3  2010-09-20 "GNU" "Linux Programmer's Manual"
35 .SH NAME
36 mktemp \- make a unique temporary filename
37 .SH SYNOPSIS
38 .nf
39 .B #include <stdlib.h>
40 .sp
41 .BI "char *mktemp(char *" template );
42 .fi
43 .sp
44 .in -4n
45 Feature Test Macro Requirements for glibc (see
46 .BR feature_test_macros (7)):
47 .in
48 .sp
49 .BR mktemp ():
50 .ad l
51 .PD 0
52 .RS 4
53 .TP 4
54 Since glibc 2.12:
55 _BSD_SOURCE || _SVID_SOURCE ||
56     (_XOPEN_SOURCE\ >=\ 500 ||
57          _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
58     !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
59 .TP
60 Before glibc 2.12:
61 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
62 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
63 .RE
64 .PD
65 .ad b
66 .SH DESCRIPTION
67 The
68 .BR mktemp ()
69 function generates a unique temporary filename
70 from \fItemplate\fP.
71 The last six characters of \fItemplate\fP must
72 be XXXXXX and these are replaced with a string that makes the
73 filename unique.
74 Since it will be modified,
75 .I template
76 must not be a string constant, but should be declared as a character array.
77 .SH RETURN VALUE
78 The
79 .BR mktemp ()
80 function always returns \fItemplate\fP.
81 If a unique name was created, the last six bytes of \fItemplate\fP will
82 have been modified in such a way that the resulting name is unique
83 (i.e., does not exist already)
84 If a unique name could not be created,
85 \fItemplate\fP is made an empty string.
86 .SH ERRORS
87 .TP
88 .B EINVAL
89 The last six characters of \fItemplate\fP were not XXXXXX.
90 .SH CONFORMING TO
91 4.3BSD, POSIX.1-2001.
92 POSIX.1-2008 removes the specification of
93 .BR mktemp ().
94 .SH NOTES
95 The prototype is in
96 .I <unistd.h>
97 for libc4, libc5, glibc1; glibc2 follows the Single UNIX Specification
98 and has the prototype in
99 .IR <stdlib.h> .
100 .SH BUGS
101 Never use
102 .BR mktemp ().
103 Some implementations follow 4.3BSD
104 and replace XXXXXX by the current process ID and a single letter,
105 so that at most 26 different names can be returned.
106 Since on the one hand the names are easy to guess, and on the other
107 hand there is a race between testing whether the name exists and
108 opening the file, every use of
109 .BR mktemp ()
110 is a security risk.
111 The race is avoided by
112 .BR mkstemp (3).
113 .SH SEE ALSO
114 .BR mkstemp (3),
115 .BR tempnam (3),
116 .BR tmpfile (3),
117 .BR tmpnam (3)