OSDN Git Service

(split) LDP: Update the version to 3.53 in PO files
[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 .TH READV 2 2010\-11\-17 Linux "Linux Programmer's Manual"
38 .SH 名前
39 readv, writev, preadv, pwritev \- 複数のバッファへの読み書きを行なう
40 .SH 書式
41 .nf
42 \fB#include <sys/uio.h>\fP
43 .sp
44 \fBssize_t readv(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB);\fP
45 .sp
46 \fBssize_t writev(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB);\fP
47 .sp
48 \fBssize_t preadv(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB,\fP
49 \fB               off_t \fP\fIoffset\fP\fB);\fP
50 .sp
51 \fBssize_t pwritev(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB,\fP
52 \fB                off_t \fP\fIoffset\fP\fB);\fP
53 .fi
54 .sp
55 .in -4n
56 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
57 .in
58 .sp
59 \fBpreadv\fP(), \fBpwritev\fP(): _BSD_SOURCE
60 .SH 説明
61 \fBreadv\fP() システムコールは、ファイルディスクリプタ \fIfd\fP に関連付けられた
62 ファイルから、 \fIiovcnt\fP 個のバッファ分のデータを読み込み、 \fIiov\fP で指定
63 されたバッファに格納する ("scatter input";「ばらまき入力」)。
64 .PP
65 \fBwritev\fP() システムコールは、 \fIiov\fP で指定されたバッファから最大 \fIiovcnt\fP
66 個のバッファ分のデータを取り出し、 ファイルディスクリプタ \fIfd\fP に関連付けら
67 れたファイルに書き込む ("gather output";「かき集め出力」)。
68 .PP
69 ポインタ \fIiov\fP は \fIiovec\fP 構造体の配列へのポインタである。 \fIiovec\fP 構造体は \fI<sys/uio.h>\fP
70 で以下のように定義されている:
71 .PP
72 .br
73 .in +4n
74 .nf
75 struct iovec {
76     void  *iov_base;    /* Starting address */
77     size_t iov_len;     /* Number of bytes to transfer */
78 };
79 .fi
80 .in
81 .PP
82 \fBreadv\fP() システムコールは、複数のバッファにデータを読み込む点を除いて
83 \fBread\fP(2) と全く同様の動作を行う。
84 .PP
85 \fBwritev\fP() システムコールは、複数のバッファのデータを書き出す点以外は
86 \fBwrite\fP(2) と全く同様の動作を行う。
87 .PP
88 バッファは配列の順序で処理される。これは、 \fBreadv\fP()  が \fIiov\fP[0] が完全に一杯になるまでデータを詰めてから、
89 \fIiov\fP[1] などに進むことを意味する (データが十分ない場合は、 \fIiov\fP が指すバッファのいずれも一杯にならない)。 同様に、
90 \fBwritev\fP()  は \fIiov\fP[0] の内容を全部書き出してから \fIiov\fP[1] などに進む。
91 .PP
92 \fBreadv\fP()  と \fBwritev\fP()  によるデータ転送は atomic に行われる。つまり、 \fBwritev\fP()
93 によるデータ書き込みは一つのブロックとして行われ、他のプロセスの write による書き込みと混ざり合うことはない (例外に関しては
94 \fBpipe\fP(7)  を参照のこと)。同様に、 \fBreadv\fP()  はファイルから連続するデータブロックが読み出すことが保証され、
95 同じファイル記述 (file description; \fBopen\fP(2)  参照) を参照するファイルディスクリプタを持つ他のスレッドやプロセスが
96 実行した read 操作の影響を受けることはない。
97 .SS "preadv() と pwritev()"
98 \fBpreadv\fP() システムコールは \fBreadv\fP() と \fBpreadv\fP(2) の機能を
99 組み合わせたものである。
100 \fBreadv\fP() と同じ処理を実行するが、
101 4 番目の引き数 \fIoffset\fP が追加されており、
102 この引き数は入力操作を行うファイルオフセットを指定する。
103
104 \fBpwritev\fP() システムコールは \fBwritev\fP() と \fBpwrite\fP(2) の機能を
105 組み合わせたものである。
106 \fBwritev\fP() と同じ処理を実行するが、
107 4 番目の引き数 \fIoffset\fP が追加されており、
108 この引き数は出力操作を行うファイルオフセットを指定する。
109
110 これらのシステムコールで、ファイルオフセットは変更されない。
111 \fIfd\fP が参照するファイルは seek 可能でなければならない。
112 .SH 返り値
113 成功した場合、 \fBreadv\fP() と \fBpreadv\fP は読み込んだバイト数を返し、
114 \fBwritev\fP() と \fBpwritev\fP()は書き込んだバイト数を返す。
115 エラーの場合 \-1 を返し、\fIerrno\fP を適切に設定する。
116 .SH エラー
117 \fBread\fP(2)  や \fBwrite\fP(2)  と同じエラーが定義されている。
118 さらに、 \fBpreadv\fP() と \fBpwritev\fP() は \fBlseek\fP(2) と同じ理由でも失敗する。
119 また、追加で以下のエラーが定義されている:
120 .TP 
121 \fBEINVAL\fP
122 \fIiov_len\fP の合計が \fIssize_t\fP の範囲をオーバーフローした。もしくは、 ベクタ数 \fIiovcnt\fP が 0
123 より小さいか許可された最大値よりも大きかった。
124 .SH バージョン
125 \fBpreadv\fP() と \fBpwritev\fP() は Linux 2.6.30 で初めて登場した。
126 ライブラリによるサポートは glibc 2.10 で追加された。
127 .SH 準拠
128 .\" The readv/writev system calls were buggy before Linux 1.3.40.
129 .\" (Says release.libc.)
130 \fBreadv\fP(), \fBwritev\fP():
131 4.4BSD (これらのシステムコールは 4.2BSD で最初に現われた)、POSIX.1\-2001。
132 Linux libc5 では、 \fIiovcnt\fP 引き数の型として \fIsize_t\fP を、
133 返り値の型として \fIint\fP を使用していた。
134
135 \fBpreadv\fP(), \fBpwritev\fP(): 非標準だが、最近の BSD にも存在する。
136 .SH 注意
137 .SS "Linux での注意"
138 POSIX.1\-2001 では、 \fIiov\fP で渡すことができる要素数に上限を設ける実装が認められている。 実装は、
139 \fI<limits.h>\fP の \fBIOV_MAX\fP を定義することや、実行時に \fIsysconf(_SC_IOV_MAX)\fP
140 の返り値経由で、この上限を広告することができる。 Linux では、この仕組みにより広告される上限は 1024 であり、
141 この値はカーネルでの上限そのものである。 一方で、glibc のラッパー関数は、その関数の内部で呼ばれるカーネル
142 システムコールがこの上限を超過して失敗したことを検出すると、 追加の動作をする。 \fBreadv\fP()  の場合、ラッパー関数は \fIiov\fP
143 で指定された全ての要素を格納できる大きさの一時バッファを割り当て、 \fBread\fP(2)  を呼び出す際にそのバッファを渡し、 そのバッファのデータを
144 \fIiov\fP の各要素の \fIiov_base\fP フィールドが指定する場所にコピーしてから、 そのバッファを解放する。 \fBwritev\fP()
145 のラッパー関数も、同じように一時バッファを使って \fBwrite\fP(2)  を呼び出す。
146 .SH バグ
147 ファイルディスクリプタに対する操作を行う \fBreadv\fP() や \fBwritev\fP() と、
148 標準入出力ライブラリの関数をごちゃまぜにして呼ぶのはお薦めしない。
149 どんな結果になるかは定義されておらず、おそらく期待する結果は
150 得られないだろう。
151 .SH 例
152 以下のサンプルコードは \fBwritev\fP()  の使用方法を示すものである。
153
154 .in +4n
155 .nf
156 char *str0 = "hello ";
157 char *str1 = "world\en";
158 struct iovec iov[2];
159 ssize_t nwritten;
160
161 iov[0].iov_base = str0;
162 iov[0].iov_len = strlen(str0);
163 iov[1].iov_base = str1;
164 iov[1].iov_len = strlen(str1);
165
166 nwritten = writev(STDOUT_FILENO, iov, 2);
167 .fi
168 .in
169 .SH 関連項目
170 \fBpread\fP(2), \fBread\fP(2), \fBwrite\fP(2)
171 .SH この文書について
172 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
173 である。プロジェクトの説明とバグ報告に関する情報は
174 http://www.kernel.org/doc/man\-pages/ に書かれている。