OSDN Git Service

(split) LDP: Update release pages
[linuxjm/LDP_man-pages.git] / release / man2 / dup.2
1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\" and Copyright (C) 1993 Michael Haardt, Ian Jackson.
3 .\" and Copyright (C) 2005, 2008 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
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 .\"*******************************************************************
37 .\"
38 .\" This file was generated with po4a. Translate the source file.
39 .\"
40 .\"*******************************************************************
41 .\"
42 .\" Japanese Version Copyright (c) 1996 Takeshi Ueno
43 .\"         all rights reserved.
44 .\" Translated 1996-07-03, Takeshi Ueno <tueno@vio.co.jp>
45 .\" Modified 1997-12-14, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
46 .\" Modified 2003-01-16, Akihiro Motoki <amotoki@dd.iij4u.or.jp>
47 .\" Updated & Modified 2004-05-19, Yuichi SATO <ysato444@yahoo.co.jp>
48 .\" Updated & Modified 2005-09-07, Akihiro MOTOKI
49 .\" Updated 2008-02-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.77
50 .\" Updated 2008-11-09, Akihiro MOTOKI, LDP v3.13
51 .\"
52 .TH DUP 2 2012\-02\-14 Linux "Linux Programmer's Manual"
53 .SH 名前
54 dup, dup2, dup3 \- ファイルディスクリプタを複製する
55 .SH 書式
56 .nf
57 \fB#include <unistd.h>\fP
58 .sp
59 \fBint dup(int \fP\fIoldfd\fP\fB);\fP
60 \fBint dup2(int \fP\fIoldfd\fP\fB, int \fP\fInewfd\fP\fB);\fP
61 .sp
62 \fB#define _GNU_SOURCE\fP             /* feature_test_macros(7) 参照 */
63 \fB#include <fcntl.h>\fP              /* 定数 O_* の定義の取得 */
64 \fB#include <unistd.h>\fP
65 .sp
66 \fBint dup3(int \fP\fIoldfd\fP\fB, int \fP\fInewfd\fP\fB, int \fP\fIflags\fP\fB);\fP
67 .fi
68 .SH 説明
69 これらのシステムコールは、ファイルディスクリプタ \fIoldfd\fP の複製を作る。
70
71 \fBdup\fP()  は最も小さい番号の未使用のディスクリプタを 新しいディスクリプタとして使用する。
72
73 \fBdup2\fP()  は \fInewfd\fP を \fIoldfd\fP の複製として作成する。 必要であれば最初に \fInewfd\fP をクローズする。
74 以下の点に注意すること。
75 .IP * 3
76 \fIoldfd\fP が有効なファイルディスクリプタでない場合、その呼び出しは失敗し、 \fInewfd\fP はクローズされない。
77 .IP *
78 \fIoldfd\fP が有効なファイルディスクリプタで、 \fInewfd\fP が \fIoldfd\fP と同じ値の場合、 \fBdup2\fP()  は何もせず、
79 \fInewfd\fP を返す。
80 .PP
81 これらのシステムコールのいずれかが成功を返した場合には、 古いファイルディスクリプタと新しいファイルディスクリプタは
82 互いに可換なものとして使うことができる。 2つのファイルディスクリプタは同じファイル記述 (description)  (\fBopen\fP(2)  参照)
83 を参照しており、したがってファイルオフセットやファイル状態フラグが 共有される。例えば、一方のディスクリプタに対して \fBlseek\fP(2)
84 を使ってファイルオフセットを変更した場合、もう一方のディスクリプタの オフセットも変化する。
85
86 2つのディスクリプタはファイルディスクリプタフラグ (close\-on\-exec flag)  を共有しない。複製されたディスクリプタの
87 close\-on\-exec flag (\fBfcntl\fP(2)  参照) は off となる。
88
89 \fBdup3\fP()  は \fBdup2\fP()  と同じだが、以下の点が異なる。
90 .IP * 3
91 呼び出し元が、新しいファイルディスクリプタに対して close\-on\-exec フラグを強制的に設定することができる。 これを行うには、
92 \fIflags\fP に \fBO_CLOEXEC\fP を指定する。 このフラグが役に立つ理由については、 \fBopen\fP(2)  の \fBO_CLOEXEC\fP
93 フラグの説明を参照のこと。
94 .IP *
95 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
96 \fIoldfd\fP が \fInewfd\fP と同じ場合、 \fBdup3\fP()  は \fBEINVAL\fP エラーで失敗する。
97 .SH 返り値
98 成功すると、これらのシステムコールは新しいディスクリプタを返す。 エラーの場合、\-1 を返し、 \fIerrno\fP を適切に設定する。
99 .SH エラー
100 .TP 
101 \fBEBADF\fP
102 \fIoldfd\fP がオープンされたファイルディスクリプタでないか、 \fInewfd\fP がファイルディスクリプタとして許される範囲から外れている。
103 .TP 
104 \fBEBUSY\fP
105 (Linux のみ)  \fBopen\fP(2)  や \fBdup\fP()  との競合状態の場合に、 \fBdup2\fP()  や \fBdup3\fP()
106 はこのエラーを返すかもしれない。
107 .TP 
108 \fBEINTR\fP
109 \fBdup2\fP()  や \fBdup3\fP()  の呼び出しがシグナルにより割り込まれた。 \fBsignal\fP(7)  参照。
110 .TP 
111 \fBEINVAL\fP
112 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
113 (\fBdup3\fP())  \fIflags\fP に無効な値が入っている。 もしくは、 \fIoldfd\fP が \fInewfd\fP と同じであった。
114 .TP 
115 \fBEMFILE\fP
116 プロセスがすでにオープンできる最大数までファイルディスクリプタ を開いていて、さらに新しいものを開こうとした。
117 .SH バージョン
118 \fBdup3\fP()  はバージョン 2.6.27 で Linux に追加された。 glibc によるサポートはバージョン 2.9 以降で利用できる。
119 .SH 準拠
120 \fBdup\fP(), \fBdup2\fP(): SVr4, 4.3BSD, POSIX.1\-2001.
121
122 .\" SVr4 documents additional
123 .\" EINTR and ENOLINK error conditions.  POSIX.1 adds EINTR.
124 .\" The EBUSY return is Linux-specific.
125 \fBdup3\fP()  は Linux 固有である。
126 .SH 注意
127 \fInewfd\fP が範囲を超えた時に返されるエラーは、 \fBdup2\fP()  と \fBfcntl(\fP..., \fBF_DUPFD\fP, ...\fB)\fP
128 では異っている。 \fBdup2\fP()  が \fBF_DUPFD\fP と同じように \fBEINVAL\fP を返すシステムもある。
129
130 \fInewfd\fP がオープンされていると、 \fBclose\fP(2)  した時に報告されるはずのエラーが失われてしまう。 \fBdup2\fP()  や
131 \fBdup3\fP()  を使う前に先ず \fInewfd\fP をクローズするようにした方がいいだろう。
132 .SH 関連項目
133 \fBclose\fP(2), \fBfcntl\fP(2), \fBopen\fP(2)
134 .SH この文書について
135 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.54 の一部
136 である。プロジェクトの説明とバグ報告に関する情報は
137 http://www.kernel.org/doc/man\-pages/ に書かれている。