readv3
Read or write data into multiple buffers
Usage
#include <sys/uio.h>
int readv(int filedes, const struct iovec *vector,
size_t count);
int writev(int filedes, const struct iovec *vector,
size_t count);
Overview
The readv() function reads count blocks from the file associated with the file descriptor filedes into the multiple buffers described by vector.
The writev() function writes at most count blocks described by vector to the file associated with the file descriptor filedes.
The pointer vector points to a struct iovec defined in <sys/uio.h> as
struct iovec {
void *iov_base; /* Starting address */
size_t iov_len; /* Number of bytes */
};
Buffers are processed in the order vector[0], vector[1], ... vector[count].
The readv() function works just like read(2) except that multiple buffers are filled.
The writev() function works just like write(2) except that multiple buffers are written out.
Return value
The readv() function returns the number of bytes or -1 on error; the writev() function returns the number of bytes written.
Errors
The readv() and writev() functions can fail and set errno to the following values:
- EBADF
-
fd is not a valid file descriptor.
- EINVAL
-
fd is unsuitable for reading (for
readv()) or writing (forwritev()).
- EFAULT
-
buf is outside the processes' address space.
- EAGAIN
-
Non-blocking I/O had been selected in the
open()call, and reading or writing could not be done immediately.
- EINTR
-
Reading or writing was interrupted before any data was transferred.
Releases
8 releases since Debian 1.1 (Buzz); the text changed 4 times.