READ(2) COMMAND REFERENCE READ(2) NAME read, readv - read input SYNOPSIS cc = read(fd, buf, nbytes) int cc, fd; char *buf; int nbytes; #include <sys/types.h> #include <sys/uio.h> cc = readv(fd, iov, iovcnt) int cc, fd; struct iovec *iov; int iovcnt; DESCRIPTION The read command attempts to read nbytes of data from the object referenced by the descriptor fd into the buffer pointed to by buf; readv performs the same action, but scatters the input data into iovcnt buffers specified by the members of the iovec array: iov[0], iov[1], ..., iov[iovcnt-1]. The readv command is not supported for raw devices (e.g. raw disks, terminals). Commands read and readv return in cc the number of bytes read. For readv, the iovec structure is defined in <sys/uio.h> as: struct iovec { caddr_t iov_base; int iov_len; }; Each iovec entry specifies the base address and length of an area in memory where data should be placed; readv always fills an area completely before proceeding to the next area. On objects capable of seeking, the read starts at a position given by the pointer associated with fd, see lseek(2). Upon return from read, the pointer is incremented by the number of bytes actually read. 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. Printed 4/6/89 1
READ(2) COMMAND REFERENCE READ(2) Upon successful completion, read and readv return the number of bytes read and number of bytes placed in the buffer. The system guarantees to read the number of bytes requested if the descriptor references a file which has that many bytes left before the end-of-file, but in no other cases. If cc = 0, then end-of-file has been reached. DIAGNOSTICS Commands read and readv fail if one or more of the following are true: [EBADF] Fd is not a valid file descriptor open for reading. [EFAULT] Buf points outside the allocated address space. [EINTR] A read from a slow device was interrupted before any data arrived by the delivery of a signal. [ENOBUFS] Fd is a socket, and the system lacks sufficient buffer space to do the read. [ENOTCONN] Fd is a socket which is not connected. [EWOULDBLOCK] Fd is in non-blocking mode, and doing the read would cause a process to block. In addition, readv may return one of the following errors: [EINVAL] Iovcnt is less than or equal to 0, or greater than 16. [EINVAL] One of the iov_len values in the iov array is negative. [EINVAL] The sum of the iov_len values in the iov array overflowed a 32 bit integer. [ENXIO] A readv command was attempted on an unsupported raw device. RETURN VALUE If successful, the number of bytes read is returned in cc. Otherwise, a -1 is returned and the global variable errno is set to indicate the error. SEE ALSO dup(2), lseek(2), open(2), pipe(2), socket(2), and socketpair(2). Printed 4/6/89 2
%%index%% na:240,76; sy:316,1799; de:2115,1881;4308,464; di:4772,1667; rv:6439,300; se:6739,231; %%index%%000000000120