OSDN Git Service

(split) DP: release pages (catch up to 3.50).
[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 .TH DUP 2 2012\-02\-14 Linux "Linux Programmer's Manual"
42 .SH 名前
43 dup, dup2, dup3 \- ファイル・ディスクリプタを複製する
44 .SH 書式
45 .nf
46 \fB#include <unistd.h>\fP
47 .sp
48 \fBint dup(int \fP\fIoldfd\fP\fB);\fP
49 \fBint dup2(int \fP\fIoldfd\fP\fB, int \fP\fInewfd\fP\fB);\fP
50 .sp
51 \fB#define _GNU_SOURCE\fP             /* feature_test_macros(7) 参照 */
52 \fB#include <fcntl.h>\fP              /* 定数 O_* の定義の取得 */
53 \fB#include <unistd.h>\fP
54 .sp
55 \fBint dup3(int \fP\fIoldfd\fP\fB, int \fP\fInewfd\fP\fB, int \fP\fIflags\fP\fB);\fP
56 .fi
57 .SH 説明
58 これらのシステムコールは、ファイル・ディスクリプタ \fIoldfd\fP の複製を作る。
59
60 \fBdup\fP()  は最も小さい番号の未使用のディスクリプタを 新しいディスクリプタとして使用する。
61
62 \fBdup2\fP()  は \fInewfd\fP を \fIoldfd\fP の複製として作成する。 必要であれば最初に \fInewfd\fP をクローズする。
63 以下の点に注意すること。
64 .IP * 3
65 \fIoldfd\fP が有効なファイルディスクリプタでない場合、その呼び出しは失敗し、 \fInewfd\fP はクローズされない。
66 .IP *
67 \fIoldfd\fP が有効なファイルディスクリプタで、 \fInewfd\fP が \fIoldfd\fP と同じ値の場合、 \fBdup2\fP()  は何もせず、
68 \fInewfd\fP を返す。
69 .PP
70 これらのシステムコールのいずれかが成功を返した場合には、 古いファイル・ディスクリプタと新しいファイル・ディスクリプタは
71 互いに可換なものとして使うことができる。 2つのファイル・ディスクリプタは同じファイル記述 (description)  (\fBopen\fP(2)
72 参照) を参照しており、したがってファイルオフセットやファイル状態フラグが 共有される。例えば、一方のディスクリプタに対して \fBlseek\fP(2)
73 を使ってファイルオフセットを変更した場合、もう一方のディスクリプタの オフセットも変化する。
74
75 2つのディスクリプタはファイル・ディスクリプタ・フラグ (close\-on\-exec flag)  を共有しない。複製されたディスクリプタの
76 close\-on\-exec flag (\fBfcntl\fP(2)  参照) は off となる。
77
78 \fBdup3\fP()  は \fBdup2\fP()  と同じだが、以下の点が異なる。
79 .IP * 3
80 呼び出し元が、新しいファイル・ディスクリプタに対して close\-on\-exec フラグを強制的に設定することができる。 これを行うには、
81 \fIflags\fP に \fBO_CLOEXEC\fP を指定する。 このフラグが役に立つ理由については、 \fBopen\fP(2)  の \fBO_CLOEXEC\fP
82 フラグの説明を参照のこと。
83 .IP *
84 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
85 \fIoldfd\fP が \fInewfd\fP と同じ場合、 \fBdup3\fP()  は \fBEINVAL\fP エラーで失敗する。
86 .SH 返り値
87 成功すると、これらのシステムコールは新しいディスクリプタを返す。 エラーの場合、\-1 を返し、 \fIerrno\fP を適切に設定する。
88 .SH エラー
89 .TP 
90 \fBEBADF\fP
91 \fIoldfd\fP がオープンされたファイル・ディスクリプタでないか、 \fInewfd\fP がファイル・ディスクリプタとして許される範囲から外れている。
92 .TP 
93 \fBEBUSY\fP
94 (Linux のみ)  \fBopen\fP(2)  や \fBdup\fP()  との競合状態の場合に、 \fBdup2\fP()  や \fBdup3\fP()
95 はこのエラーを返すかもしれない。
96 .TP 
97 \fBEINTR\fP
98 \fBdup2\fP()  や \fBdup3\fP()  の呼び出しがシグナルにより割り込まれた。 \fBsignal\fP(7)  参照。
99 .TP 
100 \fBEINVAL\fP
101 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
102 (\fBdup3\fP())  \fIflags\fP に無効な値が入っている。 もしくは、 \fIoldfd\fP が \fInewfd\fP と同じであった。
103 .TP 
104 \fBEMFILE\fP
105 プロセスがすでにオープンできる最大数までファイル・ディスクリプタ を開いていて、さらに新しいものを開こうとした。
106 .SH バージョン
107 \fBdup3\fP()  はバージョン 2.6.27 で Linux に追加された。 glibc によるサポートはバージョン 2.9 以降で利用できる。
108 .SH 準拠
109 \fBdup\fP(), \fBdup2\fP(): SVr4, 4.3BSD, POSIX.1\-2001.
110
111 .\" SVr4 documents additional
112 .\" EINTR and ENOLINK error conditions.  POSIX.1 adds EINTR.
113 .\" The EBUSY return is Linux-specific.
114 \fBdup3\fP()  は Linux 固有である。
115 .SH 注意
116 \fInewfd\fP が範囲を超えた時に返されるエラーは、 \fBdup2\fP()  と \fBfcntl(\fP..., \fBF_DUPFD\fP, ...\fB)\fP
117 では異っている。 \fBdup2\fP()  が \fBF_DUPFD\fP と同じように \fBEINVAL\fP を返すシステムもある。
118
119 \fInewfd\fP がオープンされていると、 \fBclose\fP(2)  した時に報告されるはずのエラーが失われてしまう。 \fBdup2\fP()  や
120 \fBdup3\fP()  を使う前に先ず \fInewfd\fP をクローズするようにした方がいいだろう。
121 .SH 関連項目
122 \fBclose\fP(2), \fBfcntl\fP(2), \fBopen\fP(2)
123 .SH この文書について
124 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.50 の一部
125 である。プロジェクトの説明とバグ報告に関する情報は
126 http://www.kernel.org/doc/man\-pages/ に書かれている。