p For .Fn readv and .Fn preadv , the .Fa iovec structure is defined as:
p d -literal -offset indent -compact struct iovec { void *iov_base; size_t iov_len; }; .Ed
p Each .Fa iovec entry specifies the base address and length of an area in memory where data should be placed. .Fn readv will always fill an area completely before proceeding to the next.
p On objects capable of seeking, the .Fn read starts at a position given by the pointer associated with .Fa d (see .Xr lseek 2 ) . Upon return from .Fn read , the pointer is incremented by the number of bytes actually read.
p Objects that are not capable of seeking always read from the current position. The value of the pointer associated with such an object is undefined.
p Upon successful completion, .Fn read , .Fn readv , .Fn pread , and .Fn preadv return the number of bytes actually read and placed in the buffer. The system guarantees to read the number of bytes requested if the descriptor references a normal file that has that many bytes left before the end-of-file, but in no other case. .Sh RETURN VALUES If successful, the number of bytes actually read is returned. Upon reading end-of-file, zero is returned. Otherwise, a -1 is returned and the global variable .Va errno is set to indicate the error. .Sh ERRORS .Fn read , .Fn readv , .Fn pread , and .Fn preadv will succeed unless: l -tag -width Er t Bq Er EBADF .Fa d is not a valid file or socket descriptor open for reading. t Bq Er EFAULT .Fa buf points outside the allocated address space. t Bq Er EIO An I/O error occurred while reading from the file system. t Bq Er EINTR A read from a slow device was interrupted before any data arrived by the delivery of a signal. t Bq Er EINVAL The pointer associated with .Fa d was negative. t Bq Er EINVAL The total length of the I/O is more than can be expressed by the ssize_t return value. t Bq Er EAGAIN The file was marked for non-blocking I/O, and no data were ready to be read. .El
p In addition, .Fn readv and .Fn preadv may return one of the following errors: l -tag -width Er t Bq Er EINVAL .Fa iovcnt was less than or equal to 0, or greater than .Dv {IOV_MAX} . t Bq Er EINVAL One of the .Fa iov_len values in the .Fa iov array was negative. t Bq Er EINVAL The sum of the .Fa iov_len values in the .Fa iov array overflowed a 32-bit integer. t Bq Er EFAULT Part of the .Fa iov points outside the process's allocated address space. .El
p The .Fn pread and .Fn preadv calls may also return the following errors: l -tag -width Er t Bq Er EINVAL The specified file offset is invalid. t Bq Er ESPIPE The file descriptor is associated with a pipe, socket, or FIFO. .El .Sh SEE ALSO .Xr dup 2 , .Xr fcntl 2 , .Xr open 2 , .Xr pipe 2 , .Xr poll 2 , .Xr select 2 , .Xr socket 2 , .Xr socketpair 2 .Sh STANDARDS The .Fn read function conforms to .St -p1003.1-90 . The .Fn readv and .Fn pread functions conform to .St -xpg4.2 . .Sh HISTORY The .Fn preadv function call appeared in .Nx 1.4 . The .Fn pread function call appeared in .At V.4 . The .Fn readv function call appeared in x 4.2 . The .Fn read function call appeared in .At v6 .