read(2) [minix man page]
READ(2) System Calls Manual READ(2) NAME
read - read input SYNOPSIS
#include <sys/types.h> #include <unistd.h> ssize_t read(int d, void *buf, size_t nbytes) DESCRIPTION
Read attempts to read nbytes of data from the object referenced by the descriptor d into the buffer pointed to by buf. On objects capable of seeking, the read starts at a position given by the pointer associated with d (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. Upon successful completion, read return the number of bytes actually read and placed in the buffer. The system guarantees to read the num- ber 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. If the returned value is 0, then end-of-file has been reached. RETURN VALUE
If successful, the number of bytes actually read is returned. Otherwise, a -1 is returned and the global variable errno is set to indicate the error. ERRORS
Read will fail if one or more of the following are true: [EBADF] D is not a valid descriptor open for reading. [EFAULT] Buf points outside the allocated address space. [EIO] An I/O error occurred while reading from the file system. [EINTR] A read from a slow device was interrupted before any data arrived by the delivery of a signal. [EAGAIN] The file was marked for non-blocking I/O, and no data were ready to be read. SEE ALSO
dup(2), fcntl(2), open(2), pipe(2), write(2). 4th Berkeley Distribution May 23, 1986 READ(2)
Check Out this Related Man Page
WRITE(2) System Calls Manual WRITE(2) NAME
write - write output SYNOPSIS
#include <sys/types.h> #include <unistd.h> ssize_t write(int d, const void *buf, size_t nbytes) DESCRIPTION
Write attempts to write nbytes of data to the object referenced by the descriptor d from the buffer pointed to by buf. On objects capable of seeking, the write starts at a position given by the pointer associated with d, see lseek(2). Upon return from write, the pointer is incremented by the number of bytes actually written. Objects that are not capable of seeking always write from the current position. The value of the pointer associated with such an object is undefined. When using non-blocking I/O on objects such as TCP/IP channels that are subject to flow control, write may write fewer bytes than requested; the return value must be noted, and the remainder of the operation should be retried when possible. RETURN VALUE
Upon successful completion the number of bytes actually written is returned. Otherwise a -1 is returned and the global variable errno is set to indicate the error. ERRORS
Write will fail and the file pointer will remain unchanged if one or more of the following are true: [EBADF] D is not a valid descriptor open for writing. [EPIPE] An attempt is made to write to a pipe that is not open for reading by any process. [EPIPE] An attempt is made to write to a TCP channel that is not connected to a peer socket. [EFBIG] An attempt was made to write a file that exceeds the process's file size limit or the maximum file size. [EFAULT] Part of the data to be written to the file points outside the process's allocated address space. [ENOSPC] There is no free space remaining on the file system containing the file. [EIO] An I/O error occurred while reading from or writing to the file system. [EAGAIN] The file was marked for non-blocking I/O, and no data could be written immediately. SEE ALSO
fcntl(2), lseek(2), open(2), pipe(2), read(2). 4th Berkeley Distribution May 14, 1986 WRITE(2)