1 .\" Copyright (C) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" and (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" Modified Sat Jul 24 18:34:44 1993 by Rik Faith (faith@cs.unc.edu)
25 .\" Merged readv.[23], 2002-10-17, aeb
26 .\" 2007-04-30 mtk, A fairly major rewrite to fix errors and
29 .TH READV 2 2002-10-17 "Linux" "Linux Programmer's Manual"
31 readv, writev \- read or write data into multiple buffers
34 .B #include <sys/uio.h>
36 .BI "ssize_t readv(int " fd ", const struct iovec *" iov ", int " iovcnt );
38 .BI "ssize_t writev(int " fd ", const struct iovec *" iov ", int " iovcnt );
45 buffers from the file associated with the file descriptor
47 into the buffers described by
55 buffers of data described by
57 to the file associated with the file descriptor
74 void *iov_base; /* Starting address */
75 size_t iov_len; /* Number of bytes to transfer */
82 function works just like
84 except that multiple buffers are filled.
88 function works just like
90 except that multiple buffers are written out.
92 Buffers are processed in array order.
100 (If there is insufficient data, then not all buffers pointed to by
105 writes out the entire contents of
111 The data transfers performed by
115 are atomic: the data written by
117 is written as a single block that is not intermingled with output
118 from writes in other processes (but see
123 is guaranteed to read a contiguous block of data from the file,
124 regardless of read operations performed in other threads or processes
125 that have file descriptors referring to the same open file description
131 function returns the number of bytes read; the
133 function returns the number of bytes written.
134 On error, \-1 is returned, and \fIerrno\fP is set appropriately.
136 The errors are as given for
140 Additionally the following error is defined:
148 Or, the vector count \fIiovcnt\fP is less than zero or greater than the
155 functions first appeared in 4.2BSD), POSIX.1-2001.
156 Linux libc5 used \fIsize_t\fP as the type of the \fIiovcnt\fP parameter,
157 and \fIint\fP as return type for these functions.
158 .\" The readv/writev system calls were buggy before Linux 1.3.40.
159 .\" (Says release.libc.)
162 POSIX.1-2001 allows an implementation to place a limit on
163 the number of items that can be passed in
165 An implementation can advertise its limit by defining
169 or at run time via the return value from
170 .IR sysconf(_SC_IOV_MAX) .
171 On Linux, the limit advertised by these mechanisms is 1024,
172 which is the true kernel limit.
173 However, the glibc wrapper functions do some extra work if
174 they detect that the underlying kernel system call failed because this
178 the wrapper function allocates a temporary buffer large enough
179 for all of the items specified by
181 passes that buffer in a call to
183 copies data from the buffer to the locations specified by the
185 fields of the elements of
187 and then frees the buffer.
188 The wrapper function for
190 performs the analogous task using a temporary buffer and a call to
193 It is not advisable to mix calls to functions like
197 which operate on file descriptors, with the functions from the stdio
198 library; the results will be undefined and probably not what you want.
200 The following code sample demonstrates the use of
205 char *str0 = "hello ";
206 char *str1 = "world\\n";
210 iov[0].iov_base = str0;
211 iov[0].iov_len = strlen(str0);
212 iov[1].iov_base = str1;
213 iov[1].iov_len = strlen(str1);
215 nwritten = writev(STDOUT_FILENO, iov, 2);