OSDN Git Service

(split) LDP: draft snapshot generated from latest pthread/ja.po files.
[linuxjm/LDP_man-pages.git] / release / 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 .SH 名前
48 dup, dup2, dup3 \- ファイル・ディスクリプタを複製する
49 .SH 書式
50 .nf
51 .B #include <unistd.h>
52 .sp
53 .BI "int dup(int " oldfd );
54 .BI "int dup2(int " oldfd ", int " newfd );
55 .sp
56 .BR "#define _GNU_SOURCE" "             /* feature_test_macros(7) 参照 */"
57 .B #include <unistd.h>
58 .sp
59 .BI "int dup3(int " oldfd ", int " newfd ", int " flags );
60 .fi
61 .SH 説明
62 これらのシステムコールは、ファイル・ディスクリプタ
63 .I oldfd
64 の複製を作る。
65
66 .BR dup ()
67 は最も小さい番号の未使用のディスクリプタを
68 新しいディスクリプタとして使用する。
69
70 .BR dup2 ()
71
72 .I newfd
73
74 .I oldfd
75 の複製として作成する。
76 必要であれば最初に
77 .I newfd
78 をクローズする。
79 以下の点に注意すること。
80 .IP * 3
81 .I oldfd
82 が有効なファイルディスクリプタでない場合、その呼び出しは失敗し、
83 .I newfd
84 はクローズされない。
85 .IP *
86 .I oldfd
87 が有効なファイルディスクリプタで、
88 .I newfd
89
90 .I oldfd
91 と同じ値の場合、
92 .BR dup2 ()
93 は何もせず、
94 .I newfd
95 を返す。
96 .PP
97 これらのシステムコールのいずれかが成功を返した場合には、
98 古いファイル・ディスクリプタと新しいファイル・ディスクリプタは
99 互いに可換なものとして使うことができる。
100 2つのファイル・ディスクリプタは同じファイル記述 (description)
101 .RB ( open (2)
102 参照) を参照しており、したがってファイルオフセットやファイル状態フラグが
103 共有される。例えば、一方のディスクリプタに対して
104 .BR lseek (2)
105 を使ってファイルオフセットを変更した場合、もう一方のディスクリプタの
106 オフセットも変化する。
107
108 2つのディスクリプタはファイル・ディスクリプタ・フラグ (close-on-exec flag)
109 を共有しない。複製されたディスクリプタの
110 close-on-exec flag
111 .RB ( fcntl (2)
112 参照) は off となる。
113
114 .BR dup3 ()
115
116 .BR dup2 ()
117 と同じだが、以下の点が異なる。
118 .IP * 3
119 呼び出し元が、新しいファイル・ディスクリプタに対して
120 close-on-exec フラグを強制的に設定することができる。
121 これを行うには、
122 .I flags
123
124 .B O_CLOEXEC
125 を指定する。
126 このフラグが役に立つ理由については、
127 .BR open (2)
128
129 .B O_CLOEXEC
130 フラグの説明を参照のこと。
131 .IP *
132 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
133 .I oldfd
134
135 .I newfd
136 と同じ場合、
137 .BR dup3 ()
138
139 .B EINVAL
140 エラーで失敗する。
141 .SH 返り値
142 成功すると、これらのシステムコールは新しいディスクリプタを返す。
143 エラーの場合、\-1 を返し、
144 .I errno
145 を適切に設定する。
146 .SH エラー
147 .TP
148 .B EBADF
149 .I oldfd
150 がオープンされたファイル・ディスクリプタでないか、
151 .I newfd
152 がファイル・ディスクリプタとして許される範囲から外れている。
153 .TP
154 .B EBUSY
155 (Linux のみ)
156 .BR open (2)
157
158 .BR dup ()
159 との競合状態の場合に、
160 .BR dup2 ()
161
162 .BR dup3 ()
163 はこのエラーを返すかもしれない。
164 .TP
165 .B EINTR
166 .BR dup2 ()
167
168 .BR dup3 ()
169 の呼び出しがシグナルにより割り込まれた。
170 .BR signal (7)
171 参照。
172 .TP
173 .B EINVAL
174 .RB ( dup3 ())
175 .I flags
176 に無効な値が入っている。
177 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
178 もしくは、
179 .I oldfd
180
181 .I newfd
182 と同じであった。
183 .TP
184 .B EMFILE
185 プロセスがすでにオープンできる最大数までファイル・ディスクリプタ
186 を開いていて、さらに新しいものを開こうとした。
187 .SH バージョン
188 .BR dup3 ()
189 はバージョン 2.6.27 で Linux に追加された。
190 glibc によるサポートはバージョン 2.9 以降で利用できる。
191 .SH 準拠
192 .BR dup (),
193 .BR dup2 ():
194 SVr4, 4.3BSD, POSIX.1-2001.
195
196 .BR dup3 ()
197 は Linux 固有である。
198 .\" SVr4 には他に EINTR, ENOLINK エラー状態の記述がある。
199 .\" POSIX.1 には他に EINTR がある。
200 .\" EBUSY が返されるのは Linux 独自のものである。
201 .SH 注意
202 .I newfd
203 が範囲を超えた時に返されるエラーは、
204 .BR dup2 ()
205
206 .BR fcntl( "..., " F_DUPFD ", ..." )
207 では異っている。
208 .BR dup2 ()
209
210 .B F_DUPFD
211 と同じように
212 .B EINVAL
213 を返すシステムもある。
214
215 .I newfd
216 がオープンされていると、
217 .BR close (2)
218 した時に報告されるはずのエラーが失われてしまう。
219 .BR dup2 ()
220
221 .BR dup3 ()
222 を使う前に先ず
223 .I newfd
224 をクローズするようにした方がいいだろう。
225 .SH 関連項目
226 .BR close (2),
227 .BR fcntl (2),
228 .BR open (2)