OSDN Git Service

長音記号の修正を release に反映
[linuxjm/LDP_man-pages.git] / release / man2 / readv.2
1 .\" Copyright (C) 2007, 2010 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" and Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" Modified Sat Jul 24 18:34:44 1993 by Rik Faith (faith@cs.unc.edu)
27 .\" Merged readv.[23], 2002-10-17, aeb
28 .\" 2007-04-30 mtk, A fairly major rewrite to fix errors and
29 .\"     add more details.
30 .\" 2010-11-16, mtk, Added documentation of preadv() and pwritev()
31 .\"
32 .\"*******************************************************************
33 .\"
34 .\" This file was generated with po4a. Translate the source file.
35 .\"
36 .\"*******************************************************************
37 .\"
38 .\" Japanese Version Copyright (c) 1997-1999 HANATAKA Shinya
39 .\"         all rights reserved.
40 .\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
41 .\" Updated 1999-04-03, HANATAKA Shinya
42 .\" Updated 2003-01-14, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
43 .\" Updated 2005-10-07, Akihiro MOTOKI
44 .\" Updated 2007-06-01, Akihiro MOTOKI, LDP v2.50
45 .\" Updated 2012-05-08, Akihiro MOTOKI <amotoki@gmail.com>
46 .\" Updated 2013-03-26, Akihiro MOTOKI <amotoki@gmail.com>
47 .\"
48 .TH READV 2 2015\-01\-22 Linux "Linux Programmer's Manual"
49 .SH 名前
50 readv, writev, preadv, pwritev \- 複数のバッファーへの読み書きを行なう
51 .SH 書式
52 .nf
53 \fB#include <sys/uio.h>\fP
54 .sp
55 \fBssize_t readv(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB);\fP
56 .sp
57 \fBssize_t writev(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB);\fP
58 .sp
59 \fBssize_t preadv(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB,\fP
60 \fB               off_t \fP\fIoffset\fP\fB);\fP
61 .sp
62 \fBssize_t pwritev(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB,\fP
63 \fB                off_t \fP\fIoffset\fP\fB);\fP
64 .fi
65 .sp
66 .in -4n
67 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
68 .in
69 .sp
70 \fBpreadv\fP(), \fBpwritev\fP(): _BSD_SOURCE
71 .SH 説明
72 \fBreadv\fP() システムコールは、ファイルディスクリプター \fIfd\fP に関連付けられた
73 ファイルから、 \fIiovcnt\fP 個のバッファー分のデータを読み込み、 \fIiov\fP で指定
74 されたバッファーに格納する ("scatter input";「ばらまき入力」)。
75 .PP
76 \fBwritev\fP() システムコールは、 \fIiov\fP で指定されたバッファーから最大 \fIiovcnt\fP
77 個のバッファー分のデータを取り出し、 ファイルディスクリプター \fIfd\fP に関連付けら
78 れたファイルに書き込む ("gather output";「かき集め出力」)。
79 .PP
80 ポインター \fIiov\fP は \fIiovec\fP 構造体の配列へのポインターである。 \fIiovec\fP 構造体は
81 \fI<sys/uio.h>\fP で以下のように定義されている:
82 .PP
83 .br
84 .in +4n
85 .nf
86 struct iovec {
87     void  *iov_base;    /* Starting address */
88     size_t iov_len;     /* Number of bytes to transfer */
89 };
90 .fi
91 .in
92 .PP
93 \fBreadv\fP() システムコールは、複数のバッファーにデータを読み込む点を除いて
94 \fBread\fP(2) と全く同様の動作を行う。
95 .PP
96 \fBwritev\fP() システムコールは、複数のバッファーのデータを書き出す点以外は
97 \fBwrite\fP(2) と全く同様の動作を行う。
98 .PP
99 バッファーは配列の順序で処理される。これは、 \fBreadv\fP()  が \fIiov\fP[0] が完全に一杯になるまでデータを詰めてから、
100 \fIiov\fP[1] などに進むことを意味する (データが十分ない場合は、 \fIiov\fP が指すバッファーのいずれも一杯にならない)。 同様に、
101 \fBwritev\fP()  は \fIiov\fP[0] の内容を全部書き出してから \fIiov\fP[1] などに進む。
102 .PP
103 \fBreadv\fP()  と \fBwritev\fP()  によるデータ転送は atomic に行われる。つまり、 \fBwritev\fP()
104 によるデータ書き込みは一つのブロックとして行われ、他のプロセスの write による書き込みと混ざり合うことはない (例外に関しては
105 \fBpipe\fP(7)  を参照のこと)。同様に、 \fBreadv\fP()  はファイルから連続するデータブロックが読み出すことが保証され、
106 同じファイル記述 (file description; \fBopen\fP(2)  参照) を参照するファイルディスクリプターを持つ他のスレッドやプロセスが
107 実行した read 操作の影響を受けることはない。
108 .SS "preadv() と pwritev()"
109 \fBpreadv\fP() システムコールは \fBreadv\fP() と \fBpreadv\fP(2) の機能を
110 組み合わせたものである。
111 \fBreadv\fP() と同じ処理を実行するが、
112 4 番目の引き数 \fIoffset\fP が追加されており、
113 この引き数は入力操作を行うファイルオフセットを指定する。
114
115 \fBpwritev\fP() システムコールは \fBwritev\fP() と \fBpwrite\fP(2) の機能を
116 組み合わせたものである。
117 \fBwritev\fP() と同じ処理を実行するが、
118 4 番目の引き数 \fIoffset\fP が追加されており、
119 この引き数は出力操作を行うファイルオフセットを指定する。
120
121 これらのシステムコールで、ファイルオフセットは変更されない。
122 \fIfd\fP が参照するファイルは seek 可能でなければならない。
123 .SH 返り値
124 成功した場合、 \fBreadv\fP() と \fBpreadv\fP は読み込んだバイト数を返し、
125 \fBwritev\fP() と \fBpwritev\fP()は書き込んだバイト数を返す。
126 エラーの場合 \-1 を返し、\fIerrno\fP を適切に設定する。
127 .SH エラー
128 \fBread\fP(2)  や \fBwrite\fP(2)  と同じエラーが定義されている。
129 さらに、 \fBpreadv\fP() と \fBpwritev\fP() は \fBlseek\fP(2) と同じ理由でも失敗する。
130 また、追加で以下のエラーが定義されている:
131 .TP 
132 \fBEINVAL\fP
133 \fIiov_len\fP の合計が \fIssize_t\fP の範囲をオーバーフローした。
134 .TP 
135 \fBEINVAL\fP
136 ベクタ数 \fIiovcnt\fP が 0 より小さいか許可された最大値よりも大きかった。
137 .SH バージョン
138 \fBpreadv\fP() と \fBpwritev\fP() は Linux 2.6.30 で初めて登場した。
139 ライブラリによるサポートは glibc 2.10 で追加された。
140 .SH 準拠
141 .\" Linux libc5 used \fIsize_t\fP as the type of the \fIiovcnt\fP argument,
142 .\" and \fIint\fP as the return type.
143 .\" The readv/writev system calls were buggy before Linux 1.3.40.
144 .\" (Says release.libc.)
145 \fBreadv\fP(), \fBwritev\fP(): 4.4BSD (これらのシステムコールは 4.2BSD で初めて登場した),
146 POSIX.1\-2001.
147
148 \fBpreadv\fP(), \fBpwritev\fP(): 非標準だが、最近の BSD にも存在する。
149 .SH 注意
150 POSIX.1\-2001 では、 \fIiov\fP で渡すことができる要素数に上限を設ける実装が認められている。 実装はこの上限値を広告することができ、
151 \fI<limits.h>\fP の \fBIOV_MAX\fP を定義することや、 実行時に \fIsysconf(_SC_IOV_MAX)\fP
152 の返り値経由で知ることができる。 最近の Linux では、 この上限値は 1024 である。 Linux 2.0 の頃は、 この値は 16 であった。
153
154
155 .\"
156 .\"
157 .SS "C ライブラリとカーネル ABI の違い"
158 素のシステムコール \fBpreadv\fP() と \fBpwritev\fP() のシグネチャーは、 「書式」に書かれている対応する GNU C
159 ライブラリのラッパー関数のものとは少し異なる。 最後の引き数 \fIoffset\fP はラッパー関数によりシステムコールの 2 つの引き数に展開される。
160
161 \fB unsigned long \fP\fIpos_l\fP\fB, unsigned long \fP\fIpos\fP
162
163 これらの引き数は、それぞれ、 \fIoffset\fP の下位 32 ビットと上位 32 ビットである。
164 .SS "以前の C ライブラリとカーネル ABI の違い"
165 古いバージョンの Linux では \fBIOV_MAX\fP が非常に小さかったという事実に対処するため、 glibc の \fBreadv\fP() と
166 \fBwritev\fP() のラッパー関数は、 その関数の内部で呼ばれるカーネルシステムコールがこの上限を超過して失敗したことを検出すると、
167 追加の動作をしていた。 \fBreadv\fP() の場合、 ラッパー関数は \fIiov\fP
168 で指定された全ての要素を格納できる大きさの一時バッファーを割り当て、 \fBread\fP(2) を呼び出す際にそのバッファーを渡し、
169 そのバッファーのデータを \fIiov\fP の各要素の \fIiov_base\fP フィールドが指定する場所にコピーしてから、 そのバッファーを解放していた。
170 \fBwritev\fP() のラッパー関数も、 同じように一時バッファーを使って \fBwrite\fP(2) を呼び出していた。
171
172 glibc ラッパー関数でのこの追加の動作は Linux 2.2 以降では必要なくなった。 しかし、 glibc はバージョン 2.10
173 まではこの動作を続けていた。 glibc 2.9 以降では、 システムがバージョン 2.6.18 より前の Linux カーネル (2.6.18
174 は勝手に選択したカーネルバージョンである) を実行しているとライブラリが検出した場合にのみ、 ラッパー関数はこの動作を行う。 glibc 2.20
175 以降では、 (Linux カーネルのバージョン 2.6.32 以降が必須条件となり) glibc
176 のラッパー関数は常にシステムコールを直接呼び出すようになっている。
177 .SH バグ
178 ファイルディスクリプターに対する操作を行う \fBreadv\fP() や \fBwritev\fP() と、
179 標準入出力ライブラリの関数をごちゃまぜにして呼ぶのはお薦めしない。
180 どんな結果になるかは定義されておらず、おそらく期待する結果は
181 得られないだろう。
182 .SH 例
183 以下のサンプルコードは \fBwritev\fP()  の使用方法を示すものである。
184
185 .in +4n
186 .nf
187 char *str0 = "hello ";
188 char *str1 = "world\en";
189 struct iovec iov[2];
190 ssize_t nwritten;
191
192 iov[0].iov_base = str0;
193 iov[0].iov_len = strlen(str0);
194 iov[1].iov_base = str1;
195 iov[1].iov_len = strlen(str1);
196
197 nwritten = writev(STDOUT_FILENO, iov, 2);
198 .fi
199 .in
200 .SH 関連項目
201 \fBpread\fP(2), \fBread\fP(2), \fBwrite\fP(2)
202 .SH この文書について
203 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.78 の一部
204 である。プロジェクトの説明とバグ報告に関する情報は
205 http://www.kernel.org/doc/man\-pages/ に書かれている。