OSDN Git Service

80ec150e31f9fe60550b1ac901bdf986891fb7a7
[linuxjm/LDP_man-pages.git] / draft / man3 / tmpnam.3
1 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
2 .\" Japanese Version Copyright 1997 Tenkou N. Hattori <tnh@alpsmap.co.jp>
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 .\" 2003-11-15, aeb, added tmpnam_r
25 .\"
26 .\" Japanese Version Copyright (c) 1997 Tenkou N. Hattori
27 .\"       all rights reserved.
28 .\" Translated 1997-01-18, Tenkou N. Hattori <tnh@alpsmap.co.jp>
29 .\" Updated 2000-03-15, Kentaro Shirakata <argrath@yo.rim.or.jp>
30 .\" Updated 2005-03-15, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
31 .\" Updated 2006-07-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.36
32 .\"
33 .TH TMPNAM 3  2010-09-10 "" "Linux Programmer's Manual"
34 .\"O .SH NAME
35 .SH 名前
36 .\"O tmpnam, tmpnam_r \- create a name for a temporary file
37 tmpnam, tmpnam_r \- 一時ファイルの名前を作成する
38 .\"O .SH SYNOPSIS
39 .SH 書式
40 .nf
41 .B #include <stdio.h>
42 .sp
43 .BI "char *tmpnam(char *" s );
44 .fi
45 .\"O .SH DESCRIPTION
46 .SH 説明
47 .\"O The
48 .\"O .BR tmpnam ()
49 .\"O function returns a pointer to a string that is a valid filename,
50 .\"O and such that a file with this name did not exist at some point
51 .\"O in time, so that naive programmers may think it
52 .\"O a suitable name for a temporary file.
53 .\"O If the argument
54 .\"O .I s
55 .\"O is NULL this name is generated in an internal static buffer
56 .\"O and may be overwritten by the next call to
57 .\"O .BR tmpnam ().
58 .BR tmpnam ()
59 関数は、ファイル名に使える文字列へのポインタを返す。
60 ある時点では同じ名前を持つファイルが存在しないファイル名が返されるので、
61 幼稚なプログラマはこの文字列が一時ファイルのファイル名として
62 適していると考えるかもしれない。
63 引き数
64 .I s
65 が NULL なら、この名前は内部の静的バッファに作成され、
66 次に
67 .BR tmpnam ()
68 関数が呼び出された時に上書きされる。
69 .\"O If
70 .\"O .I s
71 .\"O is not NULL, the name is copied to the character array (of length
72 .\"O at least
73 .\"O .IR L_tmpnam )
74 .\"O pointed to by
75 .\"O .I s
76 .\"O and the value
77 .\"O .I s
78 .\"O is returned in case of success.
79 .I s
80 が NULL でなければ、ファイル名は
81 .I s
82 が指す (少なくとも
83 .I L_tmpnam
84 の長さを持つ) 文字配列にコピーされ、
85 成功した場合は
86 .I s
87 が返される。
88 .LP
89 .\"O The pathname that is created, has a directory prefix
90 .\"O .IR P_tmpdir .
91 作成されるパス名は、ディレクトリの部分に
92 .I P_tmpdir
93 が使われる。
94 .\"O (Both
95 .\"O .I L_tmpnam
96 .\"O and
97 .\"O .I P_tmpdir
98 .\"O are defined in
99 .\"O .IR <stdio.h> ,
100 .\"O just like the
101 .\"O .B TMP_MAX
102 .\"O mentioned below.)
103 .RI ( L_tmpnam
104
105 .I P_tmpdir
106 は、以下で説明する
107 .B TMP_MAX
108 同様
109 .I <stdio.h>
110 で定義されている。)
111 .\"O .SH "RETURN VALUE"
112 .SH 返り値
113 .\"O The
114 .\"O .BR tmpnam ()
115 .\"O function returns a pointer to a unique temporary
116 .\"O filename, or NULL if a unique name cannot be generated.
117 .BR tmpnam ()
118 関数は一意な一時ファイル名へのポインタを返す。
119 一意なファイル名が作成できなかった場合は NULL を返す。
120 .SH エラー
121 .\"O No errors are defined.
122 エラーは定義されていない。
123 .\"O .SH "CONFORMING TO"
124 .SH 準拠
125 SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
126 .\"O POSIX.1-2008 marks
127 .\"O .BR tmpnam ()
128 .\"O as obsolete.
129 POSIX.1-2008 は
130 .BR tmpnam ()
131 を廃止予定としている。
132 .\"O .SH NOTES
133 .SH 注意
134 .\"O The
135 .\"O .BR tmpnam ()
136 .\"O function generates a different string each time it is called,
137 .\"O up to
138 .\"O .B TMP_MAX
139 .\"O times.
140 .\"O If it is called more than
141 .\"O .B TMP_MAX
142 .\"O times,
143 .\"O the behavior is implementation defined.
144 .BR tmpnam ()
145 関数は最大
146 .B TMP_MAX
147 回まで、呼び出される度に異なる文字列を作成する。
148 .B TMP_MAX
149 回以上呼び出された場合、その動作は実装依存である。
150 .LP
151 .\"O Although
152 .\"O .BR tmpnam ()
153 .\"O generates names that are difficult to guess,
154 .\"O it is nevertheless possible that between the time that
155 .\"O .BR tmpnam ()
156 .\"O returns a pathname, and the time that the program opens it,
157 .\"O another program might create that pathname using
158 .\"O .BR open (2),
159 .\"O or create it as a symbolic link.
160 .\"O This can lead to security holes.
161 .\"O To avoid such possibilities, use the
162 .\"O .BR open (2)
163 .\"O .B O_EXCL
164 .\"O flag to open the pathname.
165 .\"O Or better yet, use
166 .\"O .BR mkstemp (3)
167 .\"O or
168 .\"O .BR tmpfile (3).
169 .BR tmpnam ()
170 は推測が難しい名前を生成するが、それにもかかわらず、
171 .BR tmpnam ()
172 がパス名を返してから、プログラムがそのファイルをオープンする
173 までの間に、別のプログラムが同じパス名で、ファイルを
174 .BR open (2)
175 で作成したり、シンボリックリンクを作成したりする可能性がある。
176 これはセキュリティホールにつながる可能性がある。
177 そのような可能性を回避するためには、
178 .BR open (2)
179
180 .B O_EXCL
181 フラグを使ってパス名をオープンすればよい。
182 もっといいのは、
183 .BR mkstemp (3)
184
185 .BR tmpfile (3)
186 を使うことである。
187 .LP
188 .\"O Portable applications that use threads cannot call
189 .\"O .BR tmpnam ()
190 .\"O with a NULL parameter if either
191 .\"O .B _POSIX_THREADS
192 .\"O or
193 .\"O .B _POSIX_THREAD_SAFE_FUNCTIONS
194 .\"O is defined.
195 移植性が必要な、スレッドを使ったアプリケーションでは、
196 .B _POSIX_THREADS
197
198 .B _POSIX_THREAD_SAFE_FUNCTIONS
199 が定義されている場合に、
200 .BR tmpnam ()
201 関数を NULL 引き数で呼び出してはならない。
202 .LP
203 .\"O A POSIX draft proposed to use a function
204 .\"O .BR tmpnam_r ()
205 .\"O defined by
206 .\"O .sp
207 .\"O .nf
208 .\"O .in +4n
209 .\"O char *tmpnam_r(char *s) {
210 .\"O     return s ? tmpnam(s) : NULL;
211 .\"O }
212 .\"O .in
213 .\"O .fi
214 .\"O .sp
215 .\"O apparently as a warning not to use NULL.
216 POSIX 草案では、関数
217 .BR tmpnam_r ()
218 を使うことを提案している。
219 この関数は、以下のように定義されており、
220 NULL を使わないようにという警告の意味で NULL を別扱いしている。
221 .sp
222 .nf
223 .in +4n
224 char *
225 tmpnam_r(char *s)
226 {
227     return s ? tmpnam(s) : NULL;
228 }
229 .in
230 .fi
231 .sp
232 .\"O A few systems implement it.
233 .\"O To get a glibc prototype for this function from
234 .\"O .IR <stdio.h> ,
235 .\"O define
236 .\"O .B _SVID_SOURCE
237 .\"O or
238 .\"O .B _BSD_SOURCE
239 .\"O (before including
240 .\"O .I any
241 .\"O header file).
242 数は少ないが、この関数を実装しているシステムもある。
243 この関数の glibc のプロトタイプを
244 .I <stdio.h>
245 から得るには、
246 (「どの」ヘッダファイルをインクルードするよりも前に)
247 .B _SVID_SOURCE
248
249 .B _BSD_SOURCE
250 を定義しておく必要がある。
251 .\"O .SH BUGS
252 .SH バグ
253 .\"O Never use this function.
254 .\"O Use
255 .\"O .BR mkstemp (3)
256 .\"O or
257 .\"O .BR tmpfile (3)
258 .\"O instead.
259 決してこの関数を使ってはならない。代わりに
260 .BR mkstemp (3)
261
262 .BR tmpfile (3)
263 を使うこと。
264 .\"O .SH "SEE ALSO"
265 .SH 関連項目
266 .BR mkstemp (3),
267 .BR mktemp (3),
268 .BR tempnam (3),
269 .BR tmpfile (3)