OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / release / 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 .SH 名前
43 tempnam \- テンポラリファイルの名前を作成する
44 .SH 書式
45 .nf
46 .B #include <stdio.h>
47 .sp
48 .BI "char *tempnam(const char *" dir ", const char *" pfx );
49 .fi
50 .sp
51 .in -4n
52 glibc 向けの機能検査マクロの要件
53 .RB ( feature_test_macros (7)
54 参照):
55 .in
56 .sp
57 .BR tempnam ():
58 _BSD_SOURCE || _SVID_SOURCE
59 .SH 説明
60 .BR tempnam ()
61 関数はファイル名として正しい文字列へのポインターを返す。
62 このファイル名を持つファイルは、
63 .BR tempnam ()
64 がチェックした時点においては存在しない (しなかった)。
65 .I pfx
66 が NULL でない 5 バイト以内の文字列であれば、
67 生成されるパス名のうちのファイル名の部分は
68 .I pfx
69 から始まるものになる。
70 生成されるディレクトリの部分は、「適切」でなければならない
71 (大抵の場合、「適切」であるためにはまず少なくとも
72 書き込み可能でなければならない)。
73
74 適切なディレクトリの探索は、以下の手順にしたがって行われる。
75 .TP 3
76 a)
77 環境変数
78 .B TMPDIR
79 が設定されていて、
80 その内容が適切なディレクトリの名前なら、それを用いる。
81 .TP
82 b)
83 それ以外の場合、
84 .I dir
85 引き数が NULL でない文字列でかつ適切なら、それを用いる。
86 .TP
87 c)
88 それ以外の場合、
89 .RI ( <stdio.h>
90 で定義されている)
91 .I P_tmpdir
92 が適切なら、それを用いる。
93 .TP
94 d)
95 最後に実装で定義されたディレクトリが用いられることになる。
96 .PP
97 .BR tempnam ()
98 が返す文字列は
99 .BR malloc (3)
100 を使って確保される。そのため、
101 .BR free (3)
102 で解放すべきである。
103 .SH 返り値
104 .BR tempnam ()
105 関数は他と重ならないテンポラリファイル名へのポインタを返す。
106 他と重ならない名前が生成できなければ NULL を返す。
107 .SH エラー
108 .TP
109 .B ENOMEM
110 保存領域の割り当てに失敗した。
111 .SH 準拠
112 SVr4, 4.3BSD, POSIX.1-2001.
113 POSIX.1-2008 は
114 .BR tempnam ()
115 を廃止予定としている。
116 .SH 注意
117 .BR tempnam ()
118 は推測が難しい名前を生成するが、それにもかかわらず、
119 .BR tempnam ()
120 がパス名を返してから、プログラムがそのファイルをオープンする
121 までの間に、別のプログラムが同じパス名で、ファイルを
122 .BR open (2)
123 で作成したり、シンボリックリンクを作成したりする可能性がある。
124 これはセキュリティホールにつながる可能性がある。
125 そのような可能性を回避するためには、
126 .BR open (2)
127
128 .B O_EXCL
129 フラグを使ってパス名をオープンすればよい。
130 もっといいのは、
131 .BR mkstemp (3)
132
133 .BR tmpfile (3)
134 を使うことである。
135
136 SUSv2 では
137 .B TMPDIR
138 に付いて言及されていない。
139 glibc は、プログラムが set-user-ID されていない場合に限ってこれを用いる。
140 SVr4 では \fBd)\fP で使用されるディレクトリを
141 .I /tmp
142 と定めている (glibc もこの通りである)。
143 .LP
144 パス名を返すのに使用するメモリを動的に確保するので、
145 .BR tmpnam (3)
146 と違い、
147 .BR tempnam ()
148 はリエントラントであり、スレッドセーフである。
149 .LP
150 .BR tempnam ()
151 関数は最大
152 .B TMP_MAX
153 回まで、呼び出される度に異なる文字列を作成する
154 .RB ( TMP_MAX
155
156 .I <stdio.h>
157 で定義されている)。
158 もし
159 .B TMP_MAX
160 回以上呼び出された場合、動作は実装依存である。
161 .LP
162 .BR tempnam ()
163 は最大で
164 .I pfx
165 の先頭 5 バイトを使用する。
166
167 他と重ならない名前が見つけられなかった場合、glibc の
168 .BR tempnam ()
169 の実装はエラー
170 .B EEXIST
171 で失敗する。
172 .SH バグ
173 「適切」という言葉の正確な意味は定義されていない。
174 ディレクトリに対してどの程度のアクセス権限が必要なのかは指定されていない。
175
176 決してこの関数を使ってはならない。代わりに
177 .BR mkstemp (3)
178
179 .BR tmpfile (3)
180 を使うこと。
181 .SH 関連項目
182 .BR mkstemp (3),
183 .BR mktemp (3),
184 .BR tmpfile (3),
185 .BR tmpnam (3)