Open System Services System Calls Reference Manual (G06.29+, H06.08+, J06.03+)

System Functions (r) read(2)
The value returned can be less than nbytes if the number of bytes left in the file is less than
nbytes, if the read() request was interrupted by a signal, or if the file is a pipe, FIFO file, socket,
or special file and has fewer than nbytes bytes immediately available for reading. For example, a
read() from a file associated with a terminal might return one typed line of data.
No data transfer occurs past the current end-of-file (EOF). If the starting position is at or after the
end-of-file, 0 (zero) is returned.
If a write( ) or writev() call contains so much data that the file system needs to resize a pipe or
FIFO buffer, a read from that pipe or FIFO file can return up to 52 kilobytes of data, regardless of
the size of PIPE_BUF. If the buffer cannot be resized for the write operation, a read from the
pipe or FIFO file does not return more than 8192 bytes per call, regardless of the setting of
O_NONBLOCK.
When attempting to read from an empty pipe (or FIFO file):
If no process has the pipe open for writing, the read() function returns the value 0 (zero)
to indicate EOF.
If some process has the pipe open for writing:
If the O_NONBLOCK flag is not set, the read() function blocks until either
some data is written or the pipe is closed by all processes that had opened the
pipe for writing.
If the O_NONBLOCK flag is set, the read() function returns the value -1 and
sets errno to [EAGAIN].
When attempting to read from a socket and no data is currently available:
If the O_NONBLOCK flag is not set, the read() function blocks until data becomes
available or an error occurs.
If the O_NONBLOCK flag is set, the read() function returns the value -1 and sets errno
to [EWOULDBLOCK].
When attempting to read from a character special file that supports nonblocking reads, such as a
terminal, and no data is currently available:
If the O_NONBLOCK flag is not set, the read() function blocks until data becomes
available or an error occurs.
If the O_NONBLOCK flag is set, the read() function returns the value -1 and sets errno
to [EAGAIN].
If the read() function is interrupted by a signal before it reads any data, it returns the value -1
with errno set to [EINTR]. If the read() function is interrupted by a signal after it has success-
fully read some data, it returns the number of bytes read.
The read() function returns the number of bytes with the value 0 (zero) for any unwritten portion
of a regular file prior to EOF.
When reading from a device special file, the return of EOF has no effect on subsequent calls to
the read() function. When modem disconnect is detected, an EOF is returned. The errno vari-
able is not set to [EIO].
Upon successful completion, the
read() function
marks the st_atime field of the file for update.
527186-023 Hewlett-Packard Company 63