Open System Services System Calls Reference Manual (G06.25+, H06.03+)

read(2) OSS System Calls Reference Manual
NAME
read - Reads from a file
LIBRARY
G-series native OSS processes: system library
H-series OSS processes: implicit libraries
SYNOPSIS
#include <sys/types.h> /* optional except for POSIX.1 */
#include <unistd.h>
ssize_t read(
int filedes,
void *buffer,
size_t nbytes);
PARAMETERS
filedes Species an open file descriptor obtained from a successful call to the accept(),
creat(), dup( ), dup2( ), fcntl( ), open(), pipe( ), socket(),orsocketpair() func-
tion.
buffer Points to the buffer to receive data read.
nbytes Species the number of bytes to read from the file associated with the filedes
parameter.
If the value of nbytes is 0 (zero), the read() function returns 0 (zero). There are
no other results.
If the value of nbytes is greater than SSIZE_MAX, the read() function returns
-1 and sets errno to [EINVAL].
DESCRIPTION
The read() function attempts to read nbytes bytes of data from the file associated with the filedes
parameter into the buffer pointed to by the buffer parameter.
On regular files and devices capable of seeking, the read() function starts at a position in the file
given by the file pointer associated with the filedes parameter. Upon return from the read() func-
tion, the file pointer is incremented by the number of bytes actually read.
Devices that are incapable of seeking always read from the current position. For such devices,
the value of the file pointer after a call to the read() function is always 0 (zero).
Upon successful completion, the read() function returns the number of bytes actually read and
placed in the buffer. This number is never greater than the value of the nbytes parameter.
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, or spe-
cial 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):
62 Hewlett-Packard Company 527186-003