OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / 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 .\" Japanese Version Copyright (c) 1997 Kazuyuki Tanisako
34 .\"         all rights reserved.
35 .\" Translated 1997-05-17, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
36 .\" Modified 1997-05-27, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
37 .\" Modified 1998-02-05, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
38 .\" Modified 1998-09-27, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
39 .\" Modified 1999-04-10, Kazuyuki Tanisako <tanisako@osa.dec.com>
40 .\" Updated 2001-01-17, Kentaro Shirakata <argrath@ub32.org>
41 .\" Updated 2005-02-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
42 .\" Updated 2008-08-10, Akihiro MOTOKI, LDP v3.05
43 .\"
44 .\"WORD:        temporary file  °ì»þ¥Õ¥¡¥¤¥ë
45 .\"WORD:        read/write      ¥ê¡¼¥É¡¿¥é¥¤¥È
46 .\"WORD:        permissions     µö²Ä
47 .\"
48 .TH MKSTEMP 3  2008-06-19 "GNU" "Linux Programmer's Manual"
49 .\"O .SH NAME
50 .SH Ì¾Á°
51 .\"O mkstemp, mkostemp \- create a unique temporary file
52 mkstemp, mkostemp \- Â¾¤È½Å¤Ê¤é¤Ê¤¤Ì¾Á°¤ò»ý¤Ä°ì»þ¥Õ¥¡¥¤¥ë¤òºîÀ®¤¹¤ë
53 .\"O .SH SYNOPSIS
54 .SH ½ñ¼°
55 .nf
56 .B #include <stdlib.h>
57 .sp
58 .BI "int mkstemp(char *" template );
59 .sp
60 .BI "int mkostemp (char *" template ", int " flags );
61 .fi
62 .sp
63 .in -4n
64 .\"O Feature Test Macro Requirements for glibc (see
65 .\"O .BR feature_test_macros (7)):
66 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
67 .RB ( feature_test_macros (7)
68 »²¾È):
69 .in
70 .sp
71 .BR mkstemp ():
72 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500
73 .br
74 .BR mkostemp ():
75 _GNU_SOURCE
76 \"O .SH DESCRIPTION
77 .SH ÀâÌÀ
78 .\"O The
79 .\"O .BR mkstemp ()
80 .\"O function generates a unique temporary filename from
81 .\"O .IR template ,
82 .\"O creates and opens the file,
83 .\"O and returns an open file descriptor for the file.
84 ´Ø¿ô
85 .BR mkstemp ()
86 ¤Ï°ú¿ô
87 .I template
88 ¤«¤é¾¤È½Å¤Ê¤é¤Ê¤¤°ì»þ¥Õ¥¡¥¤¥ë̾¤òÀ¸À®¤·¡¢
89 ¤½¤Î¥Õ¥¡¥¤¥ë¤ÎºîÀ®¤È¥ª¡¼¥×¥ó¤ò¹Ô¤¤¡¢
90 ¤½¤Î¥Õ¥¡¥¤¥ë¤ËÂФ¹¤ë¥ª¡¼¥×¥óºÑ¤ß¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊÖ¤¹¡£
91
92 .\"O The last six characters of
93 .\"O .I template
94 .\"O must be "XXXXXX" and these are replaced with a string that makes the
95 .\"O filename unique.
96 °ú¿ô
97 .I template
98 ¤Ç»Ø¼¨¤¹¤ëʸ»úÎó¤Î¸å¤í¤Î 6 Ê¸»ú¤Ï XXXXXX ¤Ç¤¢¤ëɬÍפ¬¤¢¤ë¡£
99 ¤³¤ÎÉôʬ¤¬¥Õ¥¡¥¤¥ë̾¤ò¾¤È½Å¤Ê¤é¤Ê¤¤¤è¤¦¤Ë¤¹¤ëʸ»ú¤ÇÃÖ¤­´¹¤¨¤é¤ì¤ë¡£
100 .\"O Since it will be modified,
101 .\"O .I template
102 .\"O must not be a string constant, but should be declared as a character array.
103 .I template
104 ¤Ï½ñ¤­´¹¤¨¤é¤ì¤ë¤¿¤á¡¢Ê¸»úÎóÄê¿ô¤Ç¤Ï¤Ê¤¯Ê¸»úÇÛÎó¤È¤·¤Æ
105 Àë¸À¤¹¤ë¤è¤¦¤Ë¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
106
107 .\"O The file is created with
108 .\"O permissions 0600, that is, read plus write for owner only.
109 .\"O (In glibc versions 2.06 and earlier, the file is created with permissions 0666,
110 .\"O that is, read and write for all users.)
111 .\"O The returned file descriptor provides both read and write access to the file.
112 .\"O The file is opened with the
113 .\"O .BR open (2)
114 .\"O .B O_EXCL
115 .\"O flag, guaranteeing that the caller is the process that creates the file.
116 ¥Õ¥¡¥¤¥ë¤Ïµö²Ä¥â¡¼¥É 0600 ¤ÇºîÀ®¤µ¤ì¡¢½êÍ­¼Ô¤Î¤ß¤¬Æɤ߽ñ¤­²Äǽ¤Ç¤¢¤ë
117 (glibc ¥Ð¡¼¥¸¥ç¥ó 2.06 °ÊÁ°¤Ç¤Ï¡¢¥Õ¥¡¥¤¥ë¤Ïµö²Ä¥â¡¼¥É 0666 ¤ÇºîÀ®¤µ¤ì¡¢
118 Á´¤Æ¤Î¥æ¡¼¥¶¤¬Æɤ߽ñ¤­²Äǽ¤Ç¤¢¤Ã¤¿)¡£
119 ÊÖ¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¡¢¤³¤Î¥Õ¥¡¥¤¥ë¤Ø¤ÎÆɤ߽ñ¤­Î¾Êý¤Î¥¢¥¯¥»¥¹¤¬
120 ²Äǽ¤Ç¤¢¤ë¡£
121 ¸Æ¤Ó½Ð¤·¼Ô¤¬¤½¤Î¥Õ¥¡¥¤¥ë¤òºîÀ®¤¹¤ë¥×¥í¥»¥¹¤Ç¤¢¤ë¤³¤È¤òÊݾڤ¹¤ë¤¿¤á¤Ë¡¢
122 ¥Õ¥¡¥¤¥ë¤Ï
123 .BR open (2)
124 ¤Î
125 .B O_EXCL
126 ¥Õ¥é¥°ÉÕ¤­¤Ç¥ª¡¼¥×¥ó¤µ¤ì¤ë¡£
127
128 .\"O .BR mkostemp ()
129 .\"O is like
130 .\"O .BR mkstemp (),
131 .\"O with the difference that flags as for
132 .\"O .BR open (2)
133 .\"O may be specified in
134 .\"O .IR flags
135 .\"O (e.g.,
136 .\"O .BR O_APPEND ,
137 .\"O .BR O_SYNC ).
138 .BR mkostemp ()
139 ¤Ï
140 .BR mkstemp ()
141 ¤ÈƱÍͤÀ¤¬¡¢
142 .BR open (2)
143 ¤ËÅϤµ¤ì¤ë¥Õ¥é¥°
144 .RB O_APPEND ,
145 .B O_SYNC
146 ¤Ê¤É) ¤ò
147 .I flags
148 ¤Ç»ØÄê¤Ç¤­¤ëÅÀ¤¬°Û¤Ê¤ë
149 .\"O .SH "RETURN VALUE"
150 .SH ÊÖ¤êÃÍ
151 .\"O On success, these functions return the file descriptor
152 .\"O of the temporary file.
153 .\"O On error, \-1 is returned, and
154 .\"O .I errno
155 .\"O is set appropriately.
156 À®¸ù¤¹¤ë¤È¡¢¤³¤ì¤é¤Î´Ø¿ô¤Ï°ì»þ¥Õ¥¡¥¤¥ë¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊÖ¤¹¡£
157 ¥¨¥é¡¼¤Î¾ì¹ç¤Ï¡¢\-1 ¤òÊÖ¤·¡¢
158 .I errno
159 ¤òŬÀÚ¤ËÀßÄꤹ¤ë¡£
160 .\"O .SH ERRORS
161 .SH ¥¨¥é¡¼
162 .TP
163 .B EEXIST
164 .\"O Could not create a unique temporary filename.
165 .\"O Now the contents of \fItemplate\fP are undefined.
166 ¤¹¤Ç¤ËƱ¤¸Ì¾Á°¤ò»ý¤Ä¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤¿¡£
167 \fItemplate\fP ¤ÎÆâÍƤÏÉÔÄê¤Ç¤¢¤ë¡£
168 .TP
169 .B EINVAL
170 .\"O The last six characters of \fItemplate\fP were not XXXXXX.
171 .\"O Now \fItemplate\fP is unchanged.
172 °ú¿ô \fItemplate\fP ¤Ç»Ø¼¨¤µ¤ì¤¿Ê¸»úÇÛÎó¤Î¸å¤í¤Î 6 Ê¸»ú¤¬ XXXXXX ¤Ç¤Ê¤¤¡£
173 \fItemplate\fP ¤ÎÆâÍƤÏÊѲ½¤·¤Ê¤¤¡£
174 .PP
175 .\"O These functions may also fail with any of the errors described for
176 .\"O .BR open (2).
177 ¤³¤ì¤é¤Î´Ø¿ô¤Ï
178 .BR open (2)
179 ¤Ë½ñ¤«¤ï¤ì¤Æ¤¤¤ë¥¨¥é¡¼¤Î¤¤¤º¤ì¤«¤Ç¼ºÇÔ¤¹¤ë¤³¤È¤â¤¢¤ë¡£
180 .\"O .SH VERSIONS
181 .SH ¥Ð¡¼¥¸¥ç¥ó
182 .\"O .BR mkostemp ()
183 .\"O is available since glibc 2.7.
184 .BR mkostemp ()
185 ¤Ï glibc 2.7 °Ê¹ß¤ÇÍøÍѲÄǽ¤Ç¤¢¤ë¡£
186 .\"O .SH "CONFORMING TO"
187 .SH ½àµò
188 .BR mkstemp ():
189 4.3BSD, POSIX.1-2001.
190 .BR mkostemp ():
191 .\"O is a glibc extension.
192 glibc ¤Ë¤è¤ë³ÈÄ¥¡£
193 .\"O .SH NOTES
194 .SH Ãí°Õ
195 .\"O The old behavior of creating a file with mode 0666 may be
196 .\"O a security risk, especially since other Unix flavors use 0600,
197 .\"O and somebody might overlook this detail when porting programs.
198 µö²Ä¥â¡¼¥É 0666 ¤Ç¥Õ¥¡¥¤¥ë¤òºîÀ®¤¹¤ë¤È¤¤¤¦¸Å¤¤Æ°ºî¤Ï¡¢
199 ¥»¥­¥å¥ê¥Æ¥£¾å¤Î¥ê¥¹¥¯¤Ë¤Ê¤ë¾ì¹ç¤¬¤¢¤ë¡£
200 Æä˾¤Î Unix ¤Ç¤Ïµö²Ä¥â¡¼¥É¤È¤·¤Æ 0600 ¤ò»È¤¦¤¿¤á¡¢
201 ¥×¥í¥°¥é¥à¤ò°Ü¿¢¤¹¤ëºÝ¡¢¤³¤ÎºÙ¤«¤Ê°ã¤¤¤ò¸«Íî¤È¤¹²ÄǽÀ­¤¬
202 ¤¢¤ë¤«¤é¤À¡£
203
204 .\"O More generally, the POSIX specification of
205 .\"O .BR mkstemp ()
206 .\"O does not say anything
207 .\"O about file modes, so the application should make sure its
208 .\"O file mode creation mask (see
209 .\"O .BR umask (2))
210 .\"O is set appropriately before calling
211 .\"O .BR mkstemp ()
212 .\"O (and
213 .\"O .BR mkostemp ()).
214 ¤è¤ê°ìÈÌŪ¤Ë¤Ï¡¢
215 .BR mkstemp ()
216 ¤Î POSIX µ¬Äê¤Ç¤Ï¥Õ¥¡¥¤¥ë¥â¡¼¥É¤Ë¤Ä¤¤¤Æ²¿¤â½Ò¤Ù¤Æ¤¤¤Ê¤¤¡£
217 ½¾¤Ã¤Æ¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï
218 .BR mkstemp ()
219 (¤ä
220 .BR mkostemp ())
221 ¤ò¸Æ¤Ó½Ð¤¹Á°¤Ë¥Õ¥¡¥¤¥ë¥â¡¼¥ÉÀ¸À®¥Þ¥¹¥¯
222 .RB ( umask (2)
223 »²¾È) ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¤«³Îǧ¤¹¤ë¤Ù¤­¤Ç¤¢¤ë¡£
224
225 .\"O The prototype for
226 .\"O .BR mktemp ()
227 .\"O is in
228 .\"O .I <unistd.h>
229 .\"O for libc4, libc5, glibc1; glibc2 follows POSIX.1 and has the prototype in
230 .\"O .IR <stdlib.h> .
231 .BR mktemp ()
232 ¤Î¥×¥í¥È¥¿¥¤¥×Àë¸À¤Ï¡¢libc4, libc5, glibc1 ¤Ç¤Ï
233 .I <unistd.h>
234 ¤Ë´Þ¤Þ¤ì¤ë; glibc2 ¤Ç¤Ï POSIX.1 ¤Ë½àµò¤·
235 .I <stdlib.h>
236 ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë¡£
237 .\"O .SH "SEE ALSO"
238 .SH ´ØÏ¢¹àÌÜ
239 .BR mkdtemp (3),
240 .BR mktemp (3),
241 .BR tempnam (3),
242 .BR tmpfile (3),
243 .BR tmpnam (3)