14.7. readv and writev Functions[View full width]#include <sys/uio.h> ssize_t readv(int filedes , const struct iovec *iov ![]() ssize_t writev(int filedes , const struct iovec ![]() |
Both return: number of bytes read or written, 1 on error |
void *iov_base; /* starting address of buffer */
size_t iov_len; /* size of buffer */
};
The number of elements in the iov array is specified by iovcnt . It is limited to IOV_MAX (Recall Figure 2.10). Figure 14.27 shows a picture relating the arguments to these two functions and the iovec structure.
Figure 14.27. The iovec structure for readv and writev
[View full size image]

Example
Section 20.8, in the function _db_writeidx, we need to write two buffers consecutively to a file. The second buffer to output is an argument passed by the caller, and the first buffer is one we create, containing the length of the second buffer and a file offset of other information in the file. There are three ways we can do this.
