2004-11-03 13:51:07 +00:00
|
|
|
.\" (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
|
|
|
.\"
|
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
|
|
|
.\"
|
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\" License.
|
|
|
|
.\" Modified Sat Jul 24 18:34:44 1993 by Rik Faith (faith@cs.unc.edu)
|
|
|
|
.\" Merged readv.[23], 2002-10-17, aeb
|
|
|
|
.\"
|
|
|
|
.TH READV 2 2002-10-17 "" "Linux Programmer's Manual"
|
|
|
|
.SH NAME
|
|
|
|
readv, writev \- read or write data into multiple buffers
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <sys/uio.h>
|
|
|
|
.sp
|
|
|
|
.BI "ssize_t readv(int " fd ", const struct iovec *" vector ", int " count );
|
|
|
|
.sp
|
|
|
|
.BI "ssize_t writev(int " fd ", const struct iovec *" vector ", int " count );
|
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
|
|
|
The
|
2005-08-09 17:32:16 +00:00
|
|
|
.BR readv ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function reads
|
|
|
|
.I count
|
|
|
|
blocks from the file associated with the file descriptor
|
|
|
|
.I fd
|
|
|
|
into the multiple buffers described by
|
|
|
|
.IR vector .
|
|
|
|
.PP
|
|
|
|
The
|
2005-08-09 17:32:16 +00:00
|
|
|
.BR writev ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function writes at most
|
|
|
|
.I count
|
|
|
|
blocks described by
|
|
|
|
.I vector
|
|
|
|
to the file associated with the file descriptor
|
|
|
|
.IR fd .
|
|
|
|
.PP
|
|
|
|
The pointer
|
|
|
|
.I vector
|
|
|
|
points to a
|
2005-08-09 17:32:16 +00:00
|
|
|
.I struct iovec
|
2004-11-03 13:51:07 +00:00
|
|
|
defined in
|
2005-08-09 17:32:16 +00:00
|
|
|
.I <sys/uio.h>
|
2004-11-03 13:51:07 +00:00
|
|
|
as
|
|
|
|
.PP
|
|
|
|
.br
|
2005-08-09 17:32:16 +00:00
|
|
|
.in +0.25in
|
2004-11-03 13:51:07 +00:00
|
|
|
.nf
|
|
|
|
struct iovec {
|
2005-08-09 17:32:16 +00:00
|
|
|
void *iov_base; /* Starting address */
|
|
|
|
size_t iov_len; /* Number of bytes */
|
2004-11-03 13:51:07 +00:00
|
|
|
};
|
|
|
|
.fi
|
2005-08-09 17:32:16 +00:00
|
|
|
.in 0.25in
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
|
|
|
Buffers are processed in the order specified.
|
|
|
|
.PP
|
|
|
|
The
|
2005-08-09 17:32:16 +00:00
|
|
|
.BR readv ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function works just like
|
|
|
|
.BR read (2)
|
|
|
|
except that multiple buffers are filled.
|
|
|
|
.PP
|
|
|
|
The
|
2005-08-09 17:32:16 +00:00
|
|
|
.BR writev ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function works just like
|
|
|
|
.BR write (2)
|
|
|
|
except that multiple buffers are written out.
|
|
|
|
.PP
|
|
|
|
.SH "RETURN VALUE"
|
|
|
|
On success, the
|
2005-08-09 17:32:16 +00:00
|
|
|
.BR readv ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function returns the number of bytes read; the
|
2005-08-09 17:32:16 +00:00
|
|
|
.BR writev ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function returns the number of bytes written.
|
|
|
|
On error, \-1 is returned, and \fIerrno\fP is set appropriately.
|
|
|
|
.SH ERRORS
|
|
|
|
The errors are as given for
|
|
|
|
.BR read (2)
|
|
|
|
and
|
|
|
|
.BR write (2).
|
2005-08-09 17:32:16 +00:00
|
|
|
Additionally the following error is defined:
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
The sum of the
|
|
|
|
.I iov_len
|
|
|
|
values overflows an
|
2005-08-09 17:32:16 +00:00
|
|
|
.I ssize_t
|
2004-11-03 13:51:07 +00:00
|
|
|
value. Or,
|
2005-08-09 17:32:16 +00:00
|
|
|
the vector count \fIcount\fR is less than zero or greater than the
|
|
|
|
permitted maximum.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "CONFORMING TO"
|
|
|
|
4.4BSD (the
|
2005-08-09 17:32:16 +00:00
|
|
|
.BR readv ()
|
2004-11-03 13:51:07 +00:00
|
|
|
and
|
2005-08-09 17:32:16 +00:00
|
|
|
.BR writev ()
|
2006-08-03 13:57:17 +00:00
|
|
|
functions first appeared in 4.2BSD), POSIX.1-2001.
|
2006-02-09 20:24:53 +00:00
|
|
|
Linux libc5 used \fIsize_t\fR as the type of the \fIcount\fR parameter,
|
|
|
|
and \fIint\fP as return type for these functions.
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" The readv/writev system calls were buggy before Linux 1.3.40.
|
|
|
|
.\" (Says release.libc.)
|
2005-08-09 17:32:16 +00:00
|
|
|
.SH "LINUX NOTES"
|
2006-08-03 13:57:17 +00:00
|
|
|
POSIX.1-2001 allows an implementation to place a limit on
|
|
|
|
the number of items that can be passed in
|
2005-08-09 17:32:16 +00:00
|
|
|
.IR vector .
|
|
|
|
An implementation can advertise its limit by defining
|
|
|
|
.B IOV_MAX
|
|
|
|
in
|
|
|
|
.IR <limits.h>
|
|
|
|
or at run time via the return value from
|
|
|
|
.IR sysconf(_SC_IOV_MAX) .
|
|
|
|
On Linux, the limit advertised by these mechanisms is 1024,
|
|
|
|
which is the true kernel limit.
|
|
|
|
However, the glibc wrapper functions do some extra work if
|
|
|
|
they detect that the underlying kernel system call failed because this
|
|
|
|
limit was exceeded. In the case of
|
|
|
|
.BR readv ()
|
|
|
|
the wrapper function allocates a temporary buffer large enough
|
|
|
|
for all of the items specified by
|
|
|
|
.IR vector ,
|
|
|
|
passes that buffer in a call to
|
|
|
|
.BR read (),
|
|
|
|
copies data from the buffer to the locations specified by the
|
|
|
|
.I iov_base
|
|
|
|
fields of the elements of
|
|
|
|
.IR vector ,
|
|
|
|
and then frees the buffer.
|
|
|
|
The wrapper function for
|
|
|
|
.BR writev ()
|
|
|
|
performs the analogous task using a temporary buffer and a call to
|
|
|
|
.BR write ().
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH BUGS
|
|
|
|
It is not advisable to mix calls to functions like
|
2005-08-09 17:32:16 +00:00
|
|
|
.BR readv ()
|
2004-11-03 13:51:07 +00:00
|
|
|
or
|
2005-08-09 17:32:16 +00:00
|
|
|
.BR writev (),
|
2004-11-03 13:51:07 +00:00
|
|
|
which operate on file descriptors, with the functions from the stdio
|
|
|
|
library; the results will be undefined and probably not what you want.
|
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR read (2),
|
|
|
|
.BR write (2)
|