1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (C) 2008, Michael Kerrisk <mtk.manpages@gmail.com>
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" References consulted:
25 .\" Linux libc source code
26 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
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
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
44 .\"WORD: temporary file °ì»þ¥Õ¥¡¥¤¥ë
45 .\"WORD: read/write ¥ê¡¼¥É¡¿¥é¥¤¥È
46 .\"WORD: permissions µö²Ä
48 .TH MKSTEMP 3 2008-06-19 "GNU" "Linux Programmer's Manual"
51 .\"O mkstemp, mkostemp \- create a unique temporary file
52 mkstemp, mkostemp \- ¾¤È½Å¤Ê¤é¤Ê¤¤Ì¾Á°¤ò»ý¤Ä°ì»þ¥Õ¥¡¥¤¥ë¤òºîÀ®¤¹¤ë
56 .B #include <stdlib.h>
58 .BI "int mkstemp(char *" template );
60 .BI "int mkostemp (char *" template ", int " flags );
64 .\"O Feature Test Macro Requirements for glibc (see
65 .\"O .BR feature_test_macros (7)):
66 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
67 .RB ( feature_test_macros (7)
72 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500
80 .\"O function generates a unique temporary filename from
82 .\"O creates and opens the file,
83 .\"O and returns an open file descriptor for the file.
88 ¤«¤é¾¤È½Å¤Ê¤é¤Ê¤¤°ì»þ¥Õ¥¡¥¤¥ë̾¤òÀ¸À®¤·¡¢
89 ¤½¤Î¥Õ¥¡¥¤¥ë¤ÎºîÀ®¤È¥ª¡¼¥×¥ó¤ò¹Ô¤¤¡¢
90 ¤½¤Î¥Õ¥¡¥¤¥ë¤ËÂФ¹¤ë¥ª¡¼¥×¥óºÑ¤ß¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊÖ¤¹¡£
92 .\"O The last six characters of
94 .\"O must be "XXXXXX" and these are replaced with a string that makes the
98 ¤Ç»Ø¼¨¤¹¤ëʸ»úÎó¤Î¸å¤í¤Î 6 ʸ»ú¤Ï XXXXXX ¤Ç¤¢¤ëɬÍפ¬¤¢¤ë¡£
99 ¤³¤ÎÉôʬ¤¬¥Õ¥¡¥¤¥ë̾¤ò¾¤È½Å¤Ê¤é¤Ê¤¤¤è¤¦¤Ë¤¹¤ëʸ»ú¤ÇÃÖ¤´¹¤¨¤é¤ì¤ë¡£
100 .\"O Since it will be modified,
102 .\"O must not be a string constant, but should be declared as a character array.
104 ¤Ï½ñ¤´¹¤¨¤é¤ì¤ë¤¿¤á¡¢Ê¸»úÎóÄê¿ô¤Ç¤Ï¤Ê¤¯Ê¸»úÇÛÎó¤È¤·¤Æ
105 Àë¸À¤¹¤ë¤è¤¦¤Ë¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
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
115 .\"O flag, guaranteeing that the caller is the process that creates the file.
116 ¥Õ¥¡¥¤¥ë¤Ïµö²Ä¥â¡¼¥É 0600 ¤ÇºîÀ®¤µ¤ì¡¢½êͼԤΤߤ¬Æɤ߽ñ¤²Äǽ¤Ç¤¢¤ë
117 (glibc ¥Ð¡¼¥¸¥ç¥ó 2.06 °ÊÁ°¤Ç¤Ï¡¢¥Õ¥¡¥¤¥ë¤Ïµö²Ä¥â¡¼¥É 0666 ¤ÇºîÀ®¤µ¤ì¡¢
118 Á´¤Æ¤Î¥æ¡¼¥¶¤¬Æɤ߽ñ¤²Äǽ¤Ç¤¢¤Ã¤¿)¡£
119 ÊÖ¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¡¢¤³¤Î¥Õ¥¡¥¤¥ë¤Ø¤ÎÆɤ߽ñ¤Î¾Êý¤Î¥¢¥¯¥»¥¹¤¬
121 ¸Æ¤Ó½Ð¤·¼Ô¤¬¤½¤Î¥Õ¥¡¥¤¥ë¤òºîÀ®¤¹¤ë¥×¥í¥»¥¹¤Ç¤¢¤ë¤³¤È¤òÊݾڤ¹¤ë¤¿¤á¤Ë¡¢
126 ¥Õ¥é¥°ÉÕ¤¤Ç¥ª¡¼¥×¥ó¤µ¤ì¤ë¡£
131 .\"O with the difference that flags as for
133 .\"O may be specified in
148 ¤Ç»ØÄê¤Ç¤¤ëÅÀ¤¬°Û¤Ê¤ë
149 .\"O .SH "RETURN VALUE"
151 .\"O On success, these functions return the file descriptor
152 .\"O of the temporary file.
153 .\"O On error, \-1 is returned, and
155 .\"O is set appropriately.
156 À®¸ù¤¹¤ë¤È¡¢¤³¤ì¤é¤Î´Ø¿ô¤Ï°ì»þ¥Õ¥¡¥¤¥ë¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊÖ¤¹¡£
157 ¥¨¥é¡¼¤Î¾ì¹ç¤Ï¡¢\-1 ¤òÊÖ¤·¡¢
164 .\"O Could not create a unique temporary filename.
165 .\"O Now the contents of \fItemplate\fP are undefined.
166 ¤¹¤Ç¤ËƱ¤¸Ì¾Á°¤ò»ý¤Ä¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤¿¡£
167 \fItemplate\fP ¤ÎÆâÍƤÏÉÔÄê¤Ç¤¢¤ë¡£
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 ¤ÎÆâÍƤÏÊѲ½¤·¤Ê¤¤¡£
175 .\"O These functions may also fail with any of the errors described for
179 ¤Ë½ñ¤«¤ï¤ì¤Æ¤¤¤ë¥¨¥é¡¼¤Î¤¤¤º¤ì¤«¤Ç¼ºÇÔ¤¹¤ë¤³¤È¤â¤¢¤ë¡£
183 .\"O is available since glibc 2.7.
185 ¤Ï glibc 2.7 °Ê¹ß¤ÇÍøÍѲÄǽ¤Ç¤¢¤ë¡£
186 .\"O .SH "CONFORMING TO"
189 4.3BSD, POSIX.1-2001.
191 .\"O is a glibc extension.
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 ¥×¥í¥°¥é¥à¤ò°Ü¿¢¤¹¤ëºÝ¡¢¤³¤ÎºÙ¤«¤Ê°ã¤¤¤ò¸«Íî¤È¤¹²ÄǽÀ¤¬
204 .\"O More generally, the POSIX specification of
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
210 .\"O is set appropriately before calling
213 .\"O .BR mkostemp ()).
216 ¤Î POSIX µ¬Äê¤Ç¤Ï¥Õ¥¡¥¤¥ë¥â¡¼¥É¤Ë¤Ä¤¤¤Æ²¿¤â½Ò¤Ù¤Æ¤¤¤Ê¤¤¡£
217 ½¾¤Ã¤Æ¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï
221 ¤ò¸Æ¤Ó½Ð¤¹Á°¤Ë¥Õ¥¡¥¤¥ë¥â¡¼¥ÉÀ¸À®¥Þ¥¹¥¯
223 »²¾È) ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¤«³Îǧ¤¹¤ë¤Ù¤¤Ç¤¢¤ë¡£
225 .\"O The prototype for
229 .\"O for libc4, libc5, glibc1; glibc2 follows POSIX.1 and has the prototype in
230 .\"O .IR <stdlib.h> .
232 ¤Î¥×¥í¥È¥¿¥¤¥×Àë¸À¤Ï¡¢libc4, libc5, glibc1 ¤Ç¤Ï
234 ¤Ë´Þ¤Þ¤ì¤ë; glibc2 ¤Ç¤Ï POSIX.1 ¤Ë½àµò¤·