OSDN Git Service

49eead0e2f3837086519f0a76b801857de2b145c
[linuxjm/LDP_man-pages.git] / 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)