OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / draft / man2 / dup.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\" and Copyright (C) 1993 Michael Haardt, Ian Jackson.
5 .\" and Copyright (C) 2005, 2008 Michael Kerrisk <mtk.manpages@gmail.com>
6 .\"
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
10 .\"
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
15 .\"
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein.  The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
22 .\" professionally.
23 .\"
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
26 .\"
27 .\" Modified 1993-07-21, Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1994-08-21, Michael Chastain <mec@shell.portal.com>:
29 .\"   Fixed typoes.
30 .\" Modified 1997-01-31, Eric S. Raymond <esr@thyrsus.com>
31 .\" Modified 2002-09-28, aeb
32 .\" 2009-01-12, mtk, reordered text in DESCRIPTION and added some
33 .\"     details for dup2().
34 .\" 2008-10-09, mtk: add description of dup3()
35 .\"
36 .\" Japanese Version Copyright (c) 1996 Takeshi Ueno
37 .\"         all rights reserved.
38 .\" Translated 1996-07-03, Takeshi Ueno <tueno@vio.co.jp>
39 .\" Modified 1997-12-14, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
40 .\" Modified 2003-01-16, Akihiro Motoki <amotoki@dd.iij4u.or.jp>
41 .\" Updated & Modified 2004-05-19, Yuichi SATO <ysato444@yahoo.co.jp>
42 .\" Updated & Modified 2005-09-07, Akihiro MOTOKI
43 .\" Updated 2008-02-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.77
44 .\" Updated 2008-11-09, Akihiro MOTOKI, LDP v3.13
45 .\"
46 .TH DUP 2 2010-09-10 "Linux" "Linux Programmer's Manual"
47 .\"O .SH NAME
48 .\"O dup, dup2, dup3 \- duplicate a file descriptor
49 .SH 名前
50 dup, dup2, dup3 \- ファイル・ディスクリプタを複製する
51 .\"O .SH SYNOPSIS
52 .SH 書式
53 .nf
54 .B #include <unistd.h>
55 .sp
56 .BI "int dup(int " oldfd );
57 .BI "int dup2(int " oldfd ", int " newfd );
58 .sp
59 .\"O .BR "#define _GNU_SOURCE" "             /* See feature_test_macros(7) */"
60 .BR "#define _GNU_SOURCE" "             /* feature_test_macros(7) 参照 */"
61 .B #include <unistd.h>
62 .sp
63 .BI "int dup3(int " oldfd ", int " newfd ", int " flags );
64 .fi
65 .\"O .SH DESCRIPTION
66 .SH 説明
67 .\"O These system calls create a copy of the file descriptor
68 .\"O .IR oldfd .
69 これらのシステムコールは、ファイル・ディスクリプタ
70 .I oldfd
71 の複製を作る。
72
73 .\"O .BR dup ()
74 .\"O uses the lowest-numbered unused descriptor for the new descriptor.
75 .BR dup ()
76 は最も小さい番号の未使用のディスクリプタを
77 新しいディスクリプタとして使用する。
78
79 .\"O .BR dup2 ()
80 .\"O .RI "makes " newfd " be the copy of " oldfd ", closing " newfd
81 .\"O first if necessary, but note the following:
82 .BR dup2 ()
83
84 .I newfd
85
86 .I oldfd
87 の複製として作成する。
88 必要であれば最初に
89 .I newfd
90 をクローズする。
91 以下の点に注意すること。
92 .IP * 3
93 .\"O If
94 .\"O .I oldfd
95 .\"O is not a valid file descriptor, then the call fails, and
96 .\"O .I newfd
97 .\"O is not closed.
98 .I oldfd
99 が有効なファイルディスクリプタでない場合、その呼び出しは失敗し、
100 .I newfd
101 はクローズされない。
102 .IP *
103 .\"O If
104 .\"O .I oldfd
105 .\"O is a valid file descriptor, and
106 .\"O .I newfd
107 .\"O has the same value as
108 .\"O .IR oldfd ,
109 .\"O then
110 .\"O .BR dup2 ()
111 .\"O does nothing, and returns
112 .\"O .IR newfd .
113 .I oldfd
114 が有効なファイルディスクリプタで、
115 .I newfd
116
117 .I oldfd
118 と同じ値の場合、
119 .BR dup2 ()
120 は何もせず、
121 .I newfd
122 を返す。
123 .PP
124 .\"O After a successful return from one of these system calls,
125 .\"O the old and new file descriptors may be used interchangeably.
126 .\"O They refer to the same open file description (see
127 .\"O .BR open (2))
128 .\"O and thus share file offset and file status flags;
129 .\"O for example, if the file offset is modified by using
130 .\"O .BR lseek (2)
131 .\"O on one of the descriptors, the offset is also changed for the other.
132 これらのシステムコールのいずれかが成功を返した場合には、
133 古いファイル・ディスクリプタと新しいファイル・ディスクリプタは
134 互いに可換なものとして使うことができる。
135 2つのファイル・ディスクリプタは同じファイル記述 (description)
136 .RB ( open (2)
137 参照) を参照しており、したがってファイルオフセットやファイル状態フラグが
138 共有される。例えば、一方のディスクリプタに対して
139 .BR lseek (2)
140 を使ってファイルオフセットを変更した場合、もう一方のディスクリプタの
141 オフセットも変化する。
142
143 .\"O The two descriptors do not share file descriptor flags
144 .\"O (the close-on-exec flag).
145 .\"O The close-on-exec flag
146 .\"O .RB ( FD_CLOEXEC ;
147 .\"O see
148 .\"O .BR fcntl (2))
149 .\"O for the duplicate descriptor is off.
150 2つのディスクリプタはファイル・ディスクリプタ・フラグ (close-on-exec flag)
151 を共有しない。複製されたディスクリプタの
152 close-on-exec flag
153 .RB ( fcntl (2)
154 参照) は off となる。
155
156 .\"O .BR dup3 ()
157 .\"O is the same as
158 .\"O .BR dup2 (),
159 .\"O except that:
160 .BR dup3 ()
161
162 .BR dup2 ()
163 と同じだが、以下の点が異なる。
164 .IP * 3
165 .\"O The caller can force the close-on-exec flag to be set
166 .\"O for the new file descriptor by specifying
167 .\"O .BR O_CLOEXEC
168 .\"O in
169 .\"O .IR flags .
170 .\"O See the description of the same flag in
171 .\"O .BR open (2)
172 .\"O for reasons why this may be useful.
173 呼び出し元が、新しいファイル・ディスクリプタに対して
174 close-on-exec フラグを強制的に設定することができる。
175 これを行うには、
176 .I flags
177
178 .B O_CLOEXEC
179 を指定する。
180 このフラグが役に立つ理由については、
181 .BR open (2)
182
183 .B O_CLOEXEC
184 フラグの説明を参照のこと。
185 .IP *
186 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
187 .\"O If
188 .\"O .IR oldfd
189 .\"O equals
190 .\"O .IR newfd ,
191 .\"O then
192 .\"O .BR dup3 ()
193 .\"O fails with the error
194 .\"O .BR EINVAL .
195 .I oldfd
196
197 .I newfd
198 と同じ場合、
199 .BR dup3 ()
200
201 .B EINVAL
202 エラーで失敗する。
203 .\"O .SH "RETURN VALUE"
204 .SH 返り値
205 .\"O On success, these system calls
206 .\"O return the new descriptor.
207 .\"O On error, \-1 is returned, and
208 .\"O .I errno
209 .\"O is set appropriately.
210 成功すると、これらのシステムコールは新しいディスクリプタを返す。
211 エラーの場合、\-1 を返し、
212 .I errno
213 を適切に設定する。
214 .\"O .SH ERRORS
215 .SH エラー
216 .TP
217 .\"O .B EBADF
218 .\"O .I oldfd
219 .\"O isn't an open file descriptor, or
220 .\"O .I newfd
221 .\"O is out of the allowed range for file descriptors.
222 .B EBADF
223 .I oldfd
224 がオープンされたファイル・ディスクリプタでないか、
225 .I newfd
226 がファイル・ディスクリプタとして許される範囲から外れている。
227 .TP
228 .B EBUSY
229 .\"O (Linux only) This may be returned by
230 .\"O .BR dup2 ()
231 .\"O or
232 .\"O .BR dup3 ()
233 .\"O during a race condition with
234 .\"O .BR open (2)
235 .\"O and
236 .\"O .BR dup ().
237 (Linux のみ)
238 .BR open (2)
239
240 .BR dup ()
241 との競合状態の場合に、
242 .BR dup2 ()
243
244 .BR dup3 ()
245 はこのエラーを返すかもしれない。
246 .TP
247 .B EINTR
248 .\"O The
249 .\"O .BR dup2 ()
250 .\"O or
251 .\"O .BR dup3 ()
252 .\"O call was interrupted by a signal; see
253 .\"O .BR signal (7).
254 .BR dup2 ()
255
256 .BR dup3 ()
257 の呼び出しがシグナルにより割り込まれた。
258 .BR signal (7)
259 参照。
260 .TP
261 .B EINVAL
262 .\"O .RB ( dup3 ())
263 .\"O .I flags
264 .\"O contain an invalid value.
265 .RB ( dup3 ())
266 .I flags
267 に無効な値が入っている。
268 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
269 .\"O Or,
270 .\"O .I oldfd
271 .\"O was equal to
272 .\"O .IR newfd .
273 もしくは、
274 .I oldfd
275
276 .I newfd
277 と同じであった。
278 .TP
279 .\"O .B EMFILE
280 .\"O The process already has the maximum number of file
281 .\"O descriptors open and tried to open a new one.
282 .B EMFILE
283 プロセスがすでにオープンできる最大数までファイル・ディスクリプタ
284 を開いていて、さらに新しいものを開こうとした。
285 .\"O .SH VERSIONS
286 .SH バージョン
287 .\"O .BR dup3 ()
288 .\"O was added to Linux in version 2.6.27;
289 .\"O glibc support is available starting with
290 .\"O version 2.9.
291 .BR dup3 ()
292 はバージョン 2.6.27 で Linux に追加された。
293 glibc によるサポートはバージョン 2.9 以降で利用できる。
294 .\"O .SH "CONFORMING TO"
295 .SH 準拠
296 .BR dup (),
297 .BR dup2 ():
298 SVr4, 4.3BSD, POSIX.1-2001.
299
300 .\"O .BR dup3 ()
301 .\"O is Linux-specific.
302 .BR dup3 ()
303 は Linux 固有である。
304 .\"O .\" SVr4 documents additional
305 .\"O .\" EINTR and ENOLINK error conditions.  POSIX.1 adds EINTR.
306 .\"O .\" The EBUSY return is Linux-specific.
307 .\" SVr4 には他に EINTR, ENOLINK エラー状態の記述がある。
308 .\" POSIX.1 には他に EINTR がある。
309 .\" EBUSY が返されるのは Linux 独自のものである。
310 .\"O .SH NOTES
311 .SH 注意
312 .\"O The error returned by
313 .\"O .BR dup2 ()
314 .\"O is different from that returned by
315 .\"O .BR fcntl( "..., " F_DUPFD ", ..." )
316 .\"O when
317 .\"O .I newfd
318 .\"O is out of range.
319 .\"O On some systems
320 .\"O .BR dup2 ()
321 .\"O also sometimes returns
322 .\"O .B EINVAL
323 .\"O like
324 .\"O .BR F_DUPFD .
325 .I newfd
326 が範囲を超えた時に返されるエラーは、
327 .BR dup2 ()
328
329 .BR fcntl( "..., " F_DUPFD ", ..." )
330 では異っている。
331 .BR dup2 ()
332
333 .B F_DUPFD
334 と同じように
335 .B EINVAL
336 を返すシステムもある。
337
338 .\"O If
339 .\"O .I newfd
340 .\"O was open, any errors that would have been reported at
341 .\"O .BR close 2()
342 .\"O time are lost.
343 .\"O A careful programmer will not use
344 .\"O .BR dup2 ()
345 .\"O or
346 .\"O .BR dup3 ()
347 .\"O without closing
348 .\"O .I newfd
349 .\"O first.
350 .I newfd
351 がオープンされていると、
352 .BR close (2)
353 した時に報告されるはずのエラーが失われてしまう。
354 .BR dup2 ()
355
356 .BR dup3 ()
357 を使う前に先ず
358 .I newfd
359 をクローズするようにした方がいいだろう。
360 .\"O .SH "SEE ALSO"
361 .SH 関連項目
362 .BR close (2),
363 .BR fcntl (2),
364 .BR open (2)