1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (C) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" and Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
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.
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.
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
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
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
31 .\" 1996-04-12 Tom Bjorkholm <tomb@mydata.se>
32 .\" First version written
33 .\" Modified Tue Oct 22 17:41:07 1996 by Eric S. Raymond <esr@thyrsus.com>
35 .\" Japanese Version Copyright (c) 1997-1999 HANATAKA Shinya
36 .\" all rights reserved.
37 .\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
38 .\" Updated 1999-04-03, HANATAKA Shinya
39 .\" Updated 2003-01-14, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
40 .\" Updated 2005-10-07, Akihiro MOTOKI
41 .\" Updated 2007-06-01, Akihiro MOTOKI, LDP v2.50
43 .\"WORD: vector ベクタ (vector)
44 .\"WORD: file descriptor ファイルディスクリプタ
47 .TH READV 2 2002-10-17 "Linux" "Linux Programmer's Manual"
49 .\"O readv, writev \- read or write data into multiple buffers
51 readv, writev \- 複数のバッファへの読み書きを行なう
55 .B #include <sys/uio.h>
57 .BI "ssize_t readv(int " fd ", const struct iovec *" iov ", int " iovcnt );
59 .BI "ssize_t writev(int " fd ", const struct iovec *" iov ", int " iovcnt );
67 .\"O buffers from the file associated with the file descriptor
69 .\"O into the buffers described by
71 .\"O ("scatter input").
80 ("scatter input";「ばらまき入力」)。
84 .\"O function writes at most
86 .\"O buffers described by
88 .\"O to the file associated with the file descriptor
90 .\"O ("gather output").
100 ("gather output";「かき集め出力」)。
104 .\"O points to an array of
124 void *iov_base; /* Starting address */
125 size_t iov_len; /* Number of bytes to transfer */
132 .\"O function works just like
134 .\"O except that multiple buffers are filled.
136 関数は、複数のバッファにデータを読み込む点を除いて
142 .\"O function works just like
144 .\"O except that multiple buffers are written out.
146 関数は、複数のバッファのデータを書き出す点以外は
150 .\"O Buffers are processed in array order.
153 .\"O completely fills
155 .\"O before proceeding to
158 .\"O (If there is insufficient data, then not all buffers pointed to by
163 .\"O writes out the entire contents of
165 .\"O before proceeding to
168 バッファは配列の順序で処理される。これは、
172 が完全に一杯になるまでデータを詰めてから、
177 が指すバッファのいずれも一杯にならない)。
186 .\"O The data transfers performed by
190 .\"O are atomic: the data written by
192 .\"O is written as a single block that is not intermingled with output
193 .\"O from writes in other processes (but see
195 .\"O for an exception);
198 .\"O is guaranteed to read a contiguous block of data from the file,
199 .\"O regardless of read operations performed in other threads or processes
200 .\"O that have file descriptors referring to the same open file description
206 によるデータ転送は atomic に行われる。つまり、
208 によるデータ書き込みは一つのブロックとして行われ、他のプロセスの
209 write による書き込みと混ざり合うことはない
214 はファイルから連続するデータブロックが読み出すことが保証され、
215 同じファイル記述 (file description;
217 参照) を参照するファイルディスクリプタを持つ他のスレッドやプロセスが
218 実行した read 操作の影響を受けることはない。
219 .\"O .SH "RETURN VALUE"
223 .\"O function returns the number of bytes read; the
225 .\"O function returns the number of bytes written.
226 .\"O On error, \-1 is returned, and \fIerrno\fP is set appropriately.
232 エラーの場合 \-1 を返し、\fIerrno\fP を適切に設定する。
235 .\"O The errors are as given for
243 .\"O Additionally the following error is defined:
249 .\"O values overflows an
252 .\"O Or, the vector count \fIiovcnt\fP is less than zero or greater than the
253 .\"O permitted maximum.
258 ベクタ数 \fIiovcnt\fP が 0 より小さいか許可された最大値よりも大きかった。
259 .\"O .SH "CONFORMING TO"
265 .\"O functions first appeared in 4.2BSD), POSIX.1-2001.
266 .\"O Linux libc5 used \fIsize_t\fP as the type of the \fIiovcnt\fP argument,
267 .\"O and \fIint\fP as return type for these functions.
268 .\"O .\" The readv/writev system calls were buggy before Linux 1.3.40.
269 .\"O .\" (Says release.libc.)
274 関数は 4.2BSD で最初に現われた)、POSIX.1-2001。
275 Linux libc5 では \fIiovcnt\fP 引き数の型として \fIsize_t\fP を、
276 これらの関数の返り値として \fIint\fP を使用していた。
277 .\" readv/writev システムコールは Linux 1.3.40 以前はバグだらけであった
278 .\" (と release.libc に書かれている)。
283 .\"O POSIX.1-2001 allows an implementation to place a limit on
284 .\"O the number of items that can be passed in
286 .\"O An implementation can advertise its limit by defining
290 .\"O or at run time via the return value from
291 .\"O .IR sysconf(_SC_IOV_MAX) .
292 .\"O On Linux, the limit advertised by these mechanisms is 1024,
293 .\"O which is the true kernel limit.
296 で渡すことができる要素数に上限を設ける実装が認められている。
302 .I sysconf(_SC_IOV_MAX)
303 の返り値経由で、この上限を広告することができる。
304 Linux では、この仕組みにより広告される上限は 1024 であり、
306 .\"O However, the glibc wrapper functions do some extra work if
307 .\"O they detect that the underlying kernel system call failed because this
308 .\"O limit was exceeded.
311 .\"O the wrapper function allocates a temporary buffer large enough
312 .\"O for all of the items specified by
314 .\"O passes that buffer in a call to
316 .\"O copies data from the buffer to the locations specified by the
318 .\"O fields of the elements of
320 .\"O and then frees the buffer.
321 .\"O The wrapper function for
323 .\"O performs the analogous task using a temporary buffer and a call to
325 一方で、glibc のラッパー関数は、その関数の内部で呼ばれるカーネル・
326 システムコールがこの上限を超過して失敗したことを検出すると、
331 で指定された全ての要素を格納できる大きさの一時バッファを割り当て、
338 フィールドが指定する場所にコピーしてから、
341 のラッパー関数も、同じように一時バッファを使って
346 .\"O It is not advisable to mix calls to functions like
350 .\"O which operate on file descriptors, with the functions from the stdio
351 .\"O library; the results will be undefined and probably not what you want.
355 のようなファイルディスクリプタに対する操作を行う関数と、
356 標準入出力ライブラリの関数をごちゃまぜにして呼ぶのはお薦めしない。
361 .\"O The following code sample demonstrates the use of
369 char *str0 = "hello ";
370 char *str1 = "world\\n";
374 iov[0].iov_base = str0;
375 iov[0].iov_len = strlen(str0);
376 iov[1].iov_base = str1;
377 iov[1].iov_len = strlen(str1);
379 nwritten = writev(STDOUT_FILENO, iov, 2);