OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man3 / tempnam.3
1 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
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 .\" Japanese Version Copyright (c) 1997-2000 Kazuyuki Tanisako and NAKANO Takeo
24 .\"         all rights reserved.
25 .\" Translated 1997-05-17, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
26 .\" Modified 1997-05-27, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
27 .\" Modified 1998-02-04, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
28 .\" Updated and Modified 2000-10-12, NAKANO Takeo <nakano@apm.seikei.ac.jp>
29 .\" Updated 2006-04-14, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.29
30 .\" Updated 2006-07-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.36
31 .\"
32 .\"WORD:        temporary file          ¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë
33 .\"WORD:        filename                ¥Õ¥¡¥¤¥ë̾
34 .\"WORD:        function                ´Ø¿ô
35 .\"WORD:        directory               ¥Ç¥£¥ì¥¯¥È¥ê
36 .\"WORD:        environment variable    ´Ä¶­ÊÑ¿ô
37 .\"WORD:        argument                °ú¤­¿ô
38 .\"WORD:        storage                 ÊݸÎΰè
39 .\"WORD:        pointer                 ¥Ý¥¤¥ó¥¿¡¼
40 .\"
41 .TH TEMPNAM 3  2008-08-06 "" "Linux Programmer's Manual"
42 .\"O .SH NAME
43 .SH Ì¾Á°
44 .\"O tempnam \- create a name for a temporary file
45 tempnam \- ¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤Î̾Á°¤òºîÀ®¤¹¤ë
46 .\"O .SH SYNOPSIS
47 .SH ½ñ¼°
48 .nf
49 .B #include <stdio.h>
50 .sp
51 .BI "char *tempnam(const char *" dir ", const char *" pfx );
52 .fi
53 .sp
54 .in -4n
55 .\"O Feature Test Macro Requirements for glibc (see
56 .\"O .BR feature_test_macros (7)):
57 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
58 .RB ( feature_test_macros (7)
59 »²¾È):
60 .in
61 .sp
62 .BR tempnam ():
63 _BSD_SOURCE || _SVID_SOURCE
64 .\"O .SH DESCRIPTION
65 .SH ÀâÌÀ
66 .\"O The
67 .\"O .BR tempnam ()
68 .\"O function returns a pointer to a string that is a valid filename,
69 .\"O and such that a file with this name did not exist when
70 .\"O .BR tempnam ()
71 .\"O checked.
72 .\"O The filename suffix of the pathname generated will start with
73 .\"O .I pfx
74 .\"O in case
75 .\"O .I pfx
76 .\"O is a non-NULL string of at most five bytes.
77 .\"O The directory prefix part of the pathname generated is required to
78 .\"O be "appropriate" (often that at least implies writable).
79 .BR tempnam ()
80 ´Ø¿ô¤Ï¥Õ¥¡¥¤¥ë̾¤È¤·¤ÆÀµ¤·¤¤Ê¸»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¡¼¤òÊÖ¤¹¡£
81 ¤³¤Î¥Õ¥¡¥¤¥ë̾¤ò»ý¤Ä¥Õ¥¡¥¤¥ë¤Ï¡¢
82 .BR tempnam ()
83 ¤¬¥Á¥§¥Ã¥¯¤·¤¿»þÅÀ¤Ë¤ª¤¤¤Æ¤Ï¸ºß¤·¤Ê¤¤ (¤·¤Ê¤«¤Ã¤¿)¡£
84 .I pfx
85 ¤¬ NULL ¤Ç¤Ê¤¤ 5 ¥Ð¥¤¥È°ÊÆâ¤Îʸ»úÎó¤Ç¤¢¤ì¤Ð¡¢
86 À¸À®¤µ¤ì¤ë¥Ñ¥¹Ì¾¤Î¤¦¤Á¤Î¥Õ¥¡¥¤¥ë̾¤ÎÉôʬ¤Ï
87 .I pfx
88 ¤«¤é»Ï¤Þ¤ë¤â¤Î¤Ë¤Ê¤ë¡£
89 À¸À®¤µ¤ì¤ë¥Ç¥£¥ì¥¯¥È¥ê¤ÎÉôʬ¤Ï¡¢¡ÖŬÀڡפǤʤ±¤ì¤Ð¤Ê¤é¤Ê¤¤
90 (ÂçÄñ¤Î¾ì¹ç¡¢¡ÖŬÀڡפǤ¢¤ë¤¿¤á¤Ë¤Ï¤Þ¤º¾¯¤Ê¤¯¤È¤â
91 ½ñ¤­¹þ¤ß²Äǽ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤)¡£
92
93 .\"O Attempts to find an appropriate directory go through the following
94 .\"O steps:
95 ŬÀڤʥǥ£¥ì¥¯¥È¥ê¤Îõº÷¤Ï¡¢°Ê²¼¤Î¼ê½ç¤Ë¤·¤¿¤¬¤Ã¤Æ¹Ô¤ï¤ì¤ë¡£
96 .TP 3
97 a)
98 .\"O In case the environment variable
99 .\"O .B TMPDIR
100 .\"O exists and
101 .\"O contains the name of an appropriate directory, that is used.
102 ´Ä¶­ÊÑ¿ô
103 .B TMPDIR
104 ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Æ¡¢
105 ¤½¤ÎÆâÍƤ¬Å¬Àڤʥǥ£¥ì¥¯¥È¥ê¤Î̾Á°¤Ê¤é¡¢¤½¤ì¤òÍѤ¤¤ë¡£
106 .TP
107 b)
108 .\"O Otherwise, if the
109 .\"O .I dir
110 .\"O argument is non-NULL and appropriate, it is used.
111 ¤½¤ì°Ê³°¤Î¾ì¹ç¡¢
112 .I dir
113 °ú¤­¿ô¤¬ NULL ¤Ç¤Ê¤¤Ê¸»úÎó¤Ç¤«¤ÄŬÀڤʤ顢¤½¤ì¤òÍѤ¤¤ë¡£
114 .TP
115 c)
116 .\"O Otherwise,
117 .\"O .I P_tmpdir
118 .\"O (as defined in
119 .\"O .IR <stdio.h> )
120 .\"O is used when appropriate.
121 ¤½¤ì°Ê³°¤Î¾ì¹ç¡¢
122 .RI ( <stdio.h>
123 ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë)
124 .I P_tmpdir
125 ¤¬Å¬Àڤʤ顢¤½¤ì¤òÍѤ¤¤ë¡£
126 .TP
127 d)
128 .\"O Finally an implementation-defined directory may be used.
129 ºÇ¸å¤Ë¼ÂÁõ¤ÇÄêµÁ¤µ¤ì¤¿¥Ç¥£¥ì¥¯¥È¥ê¤¬ÍѤ¤¤é¤ì¤ë¤³¤È¤Ë¤Ê¤ë¡£
130 .PP
131 .\"O The string returned by
132 .\"O .BR tempnam ()
133 .\"O is allocated using
134 .\"O .BR malloc (3)
135 .\"O and hence should be freed by
136 .\"O .BR free (3).
137 .BR tempnam ()
138 ¤¬ÊÖ¤¹Ê¸»úÎó¤Ï
139 .BR malloc (3)
140 ¤ò»È¤Ã¤Æ³ÎÊݤµ¤ì¤ë¡£¤½¤Î¤¿¤á¡¢
141 .BR free (3)
142 ¤Ç²òÊü¤¹¤Ù¤­¤Ç¤¢¤ë¡£
143 .\"O .SH "RETURN VALUE"
144 .SH ÊÖ¤êÃÍ
145 .\"O The
146 .\"O .BR tempnam ()
147 .\"O function returns a pointer to a unique temporary
148 .\"O filename, or NULL if a unique name cannot be generated.
149 .BR tempnam ()
150 ´Ø¿ô¤Ï¾¤È½Å¤Ê¤é¤Ê¤¤¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë̾¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
151 ¾¤È½Å¤Ê¤é¤Ê¤¤Ì¾Á°¤¬À¸À®¤Ç¤­¤Ê¤±¤ì¤Ð NULL ¤òÊÖ¤¹¡£
152 .\"O .SH ERRORS
153 .SH ¥¨¥é¡¼
154 .TP
155 .B ENOMEM
156 .\"O Allocation of storage failed.
157 ÊݸÎΰè¤Î³ä¤êÅö¤Æ¤Ë¼ºÇÔ¤·¤¿¡£
158 .\"O .SH "CONFORMING TO"
159 .SH ½àµò
160 SVr4, 4.3BSD, POSIX.1-2001.
161 .\"O POSIX.1-2008 marks
162 .\"O .BR tempnam ()
163 .\"O as obsolete.
164 POSIX.1-2008 ¤Ï
165 .BR tempnam ()
166 ¤òÇÑ»ßͽÄê¤È¤·¤Æ¤¤¤ë¡£
167 .\"O .SH NOTES
168 .SH Ãí°Õ
169 .\"O Although
170 .\"O .BR tempnam ()
171 .\"O generates names that are difficult to guess,
172 .\"O it is nevertheless possible that between the time that
173 .\"O .BR tempnam ()
174 .\"O returns a pathname, and the time that the program opens it,
175 .\"O another program might create that pathname using
176 .\"O .BR open (2),
177 .\"O or create it as a symbolic link.
178 .\"O This can lead to security holes.
179 .\"O To avoid such possibilities, use the
180 .\"O .BR open (2)
181 .\"O .B O_EXCL
182 .\"O flag to open the pathname.
183 .\"O Or better yet, use
184 .\"O .BR mkstemp (3)
185 .\"O or
186 .\"O .BR tmpfile (3).
187 .BR tempnam ()
188 ¤Ï¿ä¬¤¬Æñ¤·¤¤Ì¾Á°¤òÀ¸À®¤¹¤ë¤¬¡¢¤½¤ì¤Ë¤â¤«¤«¤ï¤é¤º¡¢
189 .BR tempnam ()
190 ¤¬¥Ñ¥¹Ì¾¤òÊÖ¤·¤Æ¤«¤é¡¢¥×¥í¥°¥é¥à¤¬¤½¤Î¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤¹¤ë
191 ¤Þ¤Ç¤Î´Ö¤Ë¡¢ÊÌ¤Î¥×¥í¥°¥é¥à¤¬Æ±¤¸¥Ñ¥¹Ì¾¤Ç¡¢¥Õ¥¡¥¤¥ë¤ò
192 .BR open (2)
193 ¤ÇºîÀ®¤·¤¿¤ê¡¢¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤òºîÀ®¤·¤¿¤ê¤¹¤ë²ÄǽÀ­¤¬¤¢¤ë¡£
194 ¤³¤ì¤Ï¥»¥­¥å¥ê¥Æ¥£¥Û¡¼¥ë¤Ë¤Ä¤Ê¤¬¤ë²ÄǽÀ­¤¬¤¢¤ë¡£
195 ¤½¤Î¤è¤¦¤Ê²ÄǽÀ­¤ò²óÈò¤¹¤ë¤¿¤á¤Ë¤Ï¡¢
196 .BR open (2)
197 ¤Î
198 .B O_EXCL
199 ¥Õ¥é¥°¤ò»È¤Ã¤Æ¥Ñ¥¹Ì¾¤ò¥ª¡¼¥×¥ó¤¹¤ì¤Ð¤è¤¤¡£
200 ¤â¤Ã¤È¤¤¤¤¤Î¤Ï¡¢
201 .BR mkstemp (3)
202 ¤ä
203 .BR tmpfile (3)
204 ¤ò»È¤¦¤³¤È¤Ç¤¢¤ë¡£
205
206 .\"O SUSv2 does not mention the use of
207 .\"O .BR TMPDIR ;
208 .\"O glibc will use it only
209 .\"O when the program is not set-user-ID.
210 .\"O On SVr4, the directory used under \fBd)\fP is
211 .\"O .I /tmp
212 .\"O (and this is what glibc does).
213 SUSv2 ¤Ç¤Ï
214 .B TMPDIR
215 ¤ËÉÕ¤¤¤Æ¸ÀµÚ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
216 glibc ¤Ï¡¢¥×¥í¥°¥é¥à¤¬ set-user-ID ¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¸Â¤Ã¤Æ¤³¤ì¤òÍѤ¤¤ë¡£
217 SVr4 ¤Ç¤Ï \fBd)\fP ¤Ç»ÈÍѤµ¤ì¤ë¥Ç¥£¥ì¥¯¥È¥ê¤ò
218 .I /tmp
219 ¤ÈÄê¤á¤Æ¤¤¤ë (glibc ¤â¤³¤ÎÄ̤ê¤Ç¤¢¤ë)¡£
220 .LP
221 .\"O Because it dynamically allocates memory used to return the pathname,
222 .\"O .BR tempnam ()
223 .\"O is reentrant, and thus thread safe, unlike
224 .\"O .BR tmpnam (3).
225 ¥Ñ¥¹Ì¾¤òÊÖ¤¹¤Î¤Ë»ÈÍѤ¹¤ë¥á¥â¥ê¤òưŪ¤Ë³ÎÊݤ¹¤ë¤Î¤Ç¡¢
226 .BR tmpnam (3)
227 ¤È°ã¤¤¡¢
228 .BR tempnam ()
229 ¤Ï¥ê¥¨¥ó¥È¥é¥ó¥È¤Ç¤¢¤ê¡¢¥¹¥ì¥Ã¥É¥»¡¼¥Õ¤Ç¤¢¤ë¡£
230 .LP
231 .\"O The
232 .\"O .BR tempnam ()
233 .\"O function generates a different string each time it is called,
234 .\"O up to
235 .\"O .B TMP_MAX
236 .\"O (defined in
237 .\"O .IR <stdio.h> )
238 .\"O times.
239 .\"O If it is called more than
240 .\"O .B TMP_MAX
241 .\"O times,
242 .\"O the behavior is implementation defined.
243 .BR tempnam ()
244 ´Ø¿ô¤ÏºÇÂç
245 .B TMP_MAX
246 ²ó¤Þ¤Ç¡¢¸Æ¤Ó½Ð¤µ¤ì¤ëÅ٤˰ۤʤëʸ»úÎó¤òºîÀ®¤¹¤ë
247 .RB ( TMP_MAX
248 ¤Ï
249 .I <stdio.h>
250 ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë)¡£
251 ¤â¤·
252 .B TMP_MAX
253 ²ó°Ê¾å¸Æ¤Ó½Ð¤µ¤ì¤¿¾ì¹ç¡¢Æ°ºî¤Ï¼ÂÁõ°Í¸¤Ç¤¢¤ë¡£
254 .LP
255 .\"O .BR tempnam ()
256 .\"O uses at most the first five bytes from
257 .\"O .IR pfx .
258 .BR tempnam ()
259 ¤ÏºÇÂç¤Ç
260 .I pfx
261 ¤ÎÀèƬ 5 ¥Ð¥¤¥È¤ò»ÈÍѤ¹¤ë¡£
262
263 .\"O The glibc implementation of
264 .\"O .BR tempnam ()
265 .\"O will fail with the error
266 .\"O .B EEXIST
267 .\"O upon failure to find a unique name.
268 ¾¤È½Å¤Ê¤é¤Ê¤¤Ì¾Á°¤¬¸«¤Ä¤±¤é¤ì¤Ê¤«¤Ã¤¿¾ì¹ç¡¢glibc ¤Î
269 .BR tempnam ()
270 ¤Î¼ÂÁõ¤Ï¥¨¥é¡¼
271 .B EEXIST
272 ¤Ç¼ºÇÔ¤¹¤ë¡£
273 .\"O .SH BUGS
274 .SH ¥Ð¥°
275 .\"O The precise meaning of "appropriate" is undefined;
276 .\"O it is unspecified how accessibility of a directory is determined.
277 ¡ÖŬÀڡפȤ¤¤¦¸ÀÍÕ¤ÎÀµ³Î¤Ê°ÕÌ£¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
278 ¥Ç¥£¥ì¥¯¥È¥ê¤ËÂФ·¤Æ¤É¤ÎÄøÅ٤Υ¢¥¯¥»¥¹¸¢¸Â¤¬É¬ÍפʤΤ«¤Ï»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
279
280 .\"O Never use this function.
281 .\"O Use
282 .\"O .BR mkstemp (3)
283 .\"O or
284 .\"O .BR tmpfile (3)
285 .\"O instead.
286 ·è¤·¤Æ¤³¤Î´Ø¿ô¤ò»È¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£Âå¤ï¤ê¤Ë
287 .BR mkstemp (3)
288 ¤«
289 .BR tmpfile (3)
290 ¤ò»È¤¦¤³¤È¡£
291 .\"O .SH "SEE ALSO"
292 .SH ´ØÏ¢¹àÌÜ
293 .BR mkstemp (3),
294 .BR mktemp (3),
295 .BR tmpfile (3),
296 .BR tmpnam (3)