OSDN Git Service

(split) LDP man-pages の original/ を v3.29 に更新。
[linuxjm/LDP_man-pages.git] / original / man3 / mktemp.3
1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\"     Linux libc source code
25 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\"     386BSD man pages
27 .\" Modified Sat Jul 24 18:48:06 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Modified Fri Jun 23 01:26:34 1995 by Andries Brouwer (aeb@cwi.nl)
29 .\" (prompted by Scott Burkett <scottb@IntNet.net>)
30 .\" Modified Sun Mar 28 23:44:38 1999 by Andries Brouwer (aeb@cwi.nl)
31 .\"
32 .TH MKTEMP 3  2010-09-20 "GNU" "Linux Programmer's Manual"
33 .SH NAME
34 mktemp \- make a unique temporary filename
35 .SH SYNOPSIS
36 .nf
37 .B #include <stdlib.h>
38 .sp
39 .BI "char *mktemp(char *" template );
40 .fi
41 .sp
42 .in -4n
43 Feature Test Macro Requirements for glibc (see
44 .BR feature_test_macros (7)):
45 .in
46 .sp
47 .BR mktemp ():
48 .ad l
49 .PD 0
50 .RS 4
51 .TP 4
52 Since glibc 2.12:
53 _BSD_SOURCE || _SVID_SOURCE ||
54     (_XOPEN_SOURCE\ >=\ 500 ||
55          _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
56     !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
57 .TP
58 Before glibc 2.12:
59 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
60 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
61 .RE
62 .PD
63 .ad b
64 .SH DESCRIPTION
65 The
66 .BR mktemp ()
67 function generates a unique temporary filename
68 from \fItemplate\fP.
69 The last six characters of \fItemplate\fP must
70 be XXXXXX and these are replaced with a string that makes the
71 filename unique.
72 Since it will be modified,
73 .I template
74 must not be a string constant, but should be declared as a character array.
75 .SH "RETURN VALUE"
76 The
77 .BR mktemp ()
78 function always returns \fItemplate\fP.
79 If a unique name was created, the last six bytes of \fItemplate\fP will
80 have been modified in such a way that the resulting name is unique
81 (i.e., does not exist already)
82 If a unique name could not be created,
83 \fItemplate\fP is made an empty string.
84 .SH ERRORS
85 .TP
86 .B EINVAL
87 The last six characters of \fItemplate\fP were not XXXXXX.
88 .SH "CONFORMING TO"
89 4.3BSD, POSIX.1-2001.
90 POSIX.1-2008 removes the specification of
91 .BR mktemp ().
92 .SH NOTES
93 The prototype is in
94 .I <unistd.h>
95 for libc4, libc5, glibc1; glibc2 follows the Single UNIX Specification
96 and has the prototype in
97 .IR <stdlib.h> .
98 .SH BUGS
99 Never use
100 .BR mktemp ().
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
107 .BR mktemp ()
108 is a security risk.
109 The race is avoided by
110 .BR mkstemp (3).
111 .SH "SEE ALSO"
112 .BR mkstemp (3),
113 .BR tempnam (3),
114 .BR tmpfile (3),
115 .BR tmpnam (3)