OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / original / man3 / mkstemp.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (C) 2008, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
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 .\"
24 .\" References consulted:
25 .\"     Linux libc source code
26 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27 .\"     386BSD man pages
28 .\" Modified Sat Jul 24 18:48:48 1993 by Rik Faith (faith@cs.unc.edu)
29 .\" Modified 980310, aeb
30 .\" Modified 990328, aeb
31 .\" 2008-06-19, mtk, Added mkostemp(); various other changes
32 .\"
33 .TH MKSTEMP 3  2008-06-19 "GNU" "Linux Programmer's Manual"
34 .SH NAME
35 mkstemp, mkostemp \- create a unique temporary file
36 .SH SYNOPSIS
37 .nf
38 .B #include <stdlib.h>
39 .sp
40 .BI "int mkstemp(char *" template );
41 .sp
42 .BI "int mkostemp (char *" template ", int " flags );
43 .fi
44 .sp
45 .in -4n
46 Feature Test Macro Requirements for glibc (see
47 .BR feature_test_macros (7)):
48 .in
49 .sp
50 .BR mkstemp ():
51 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500
52 .br
53 .BR mkostemp ():
54 _GNU_SOURCE
55 .SH DESCRIPTION
56 The
57 .BR mkstemp ()
58 function generates a unique temporary filename from
59 .IR template ,
60 creates and opens the file,
61 and returns an open file descriptor for the file.
62
63 The last six characters of
64 .I template
65 must be "XXXXXX" and these are replaced with a string that makes the
66 filename unique.
67 Since it will be modified,
68 .I template
69 must not be a string constant, but should be declared as a character array.
70
71 The file is created with
72 permissions 0600, that is, read plus write for owner only.
73 (In glibc versions 2.06 and earlier, the file is created with permissions 0666,
74 that is, read and write for all users.)
75 The returned file descriptor provides both read and write access to the file.
76 The file is opened with the
77 .BR open (2)
78 .B O_EXCL
79 flag, guaranteeing that the caller is the process that creates the file.
80
81 .BR mkostemp ()
82 is like
83 .BR mkstemp (),
84 with the difference that flags as for
85 .BR open (2)
86 may be specified in
87 .IR flags
88 (e.g.,
89 .BR O_APPEND ,
90 .BR O_SYNC ).
91 .SH "RETURN VALUE"
92 On success, these functions return the file descriptor
93 of the temporary file.
94 On error, \-1 is returned, and
95 .I errno
96 is set appropriately.
97 .SH ERRORS
98 .TP
99 .B EEXIST
100 Could not create a unique temporary filename.
101 Now the contents of \fItemplate\fP are undefined.
102 .TP
103 .B EINVAL
104 The last six characters of \fItemplate\fP were not XXXXXX.
105 Now \fItemplate\fP is unchanged.
106 .PP
107 These functions may also fail with any of the errors described for
108 .BR open (2).
109 .SH VERSIONS
110 .BR mkostemp ()
111 is available since glibc 2.7.
112 .SH "CONFORMING TO"
113 .BR mkstemp ():
114 4.3BSD, POSIX.1-2001.
115 .BR mkostemp ():
116 is a glibc extension.
117 .SH NOTES
118 The old behavior of creating a file with mode 0666 may be
119 a security risk, especially since other Unix flavors use 0600,
120 and somebody might overlook this detail when porting programs.
121
122 More generally, the POSIX specification of
123 .BR mkstemp ()
124 does not say anything
125 about file modes, so the application should make sure its
126 file mode creation mask (see
127 .BR umask (2))
128 is set appropriately before calling
129 .BR mkstemp ()
130 (and
131 .BR mkostemp ()).
132
133 The prototype for
134 .BR mktemp ()
135 is in
136 .I <unistd.h>
137 for libc4, libc5, glibc1; glibc2 follows POSIX.1 and has the prototype in
138 .IR <stdlib.h> .
139 .SH "SEE ALSO"
140 .BR mkdtemp (3),
141 .BR mktemp (3),
142 .BR tempnam (3),
143 .BR tmpfile (3),
144 .BR tmpnam (3)