READ(2) DOMAIN/IX Reference Manual (SYS5) READ(2)
NAME
read - read from file
USAGE
int read (fildes, buf, nbyte)
int fildes;
char *buf;
unsigned nbyte;
DESCRIPTION
Fildes is a file descriptor obtained from a creat, open,
dup, fcntl, or pipe system call.
Read attempts to read nbyte bytes from the file associated
with fildes into the buffer pointed to by buf.
On devices capable of seeking, the read starts at a position
in the file given by the file pointer associated with
fildes. Upon return from read, the file pointer is incre-
mented by the number of bytes actually read.
Devices that are incapable of seeking always read from the
current position. The value of a file pointer associated
with such a file is undefined.
Upon successful completion, read returns the number of bytes
actually read and placed in the buffer; this number may be
less than nbyte, if the file is associated with a communica-
tion line (see ioctl(2)), or if the number of bytes left in
the file is less than nbyte bytes. The call returns a value
of 0 when an end-of-file has been reached.
When attempting to read from an empty pipe (or FIFO): If
O_NDELAY is set, the read will return a 0.
If O_NDELAY is clear, the read will block until data is
written to the file or the file is no longer open for
writing.
When attempting to read a file associated with a tty that
has no data currently available:
If O_NDELAY is set, the read will return a 0.
If O_NDELAY
RETURN VALUE
Upon successful completion, read returns a non-negative
integer indicating the number of bytes actually read. Oth-
erwise, it returns a -1 and sets errno to indicate the
error.
Printed 5/10/85 READ-1
READ(2) DOMAIN/IX Reference Manual (SYS5) READ(2)
ERRORS
Read will fail if one or more of the following is true:
[EBADF] Fildes is not a valid file descriptor open
for reading.
[EFAULT] Buf points outside the allocated address
space.
[EINTR] A signal was caught during the read system
call.
RELATED INFORMATION
creat(2) dup(2), fcntl(2), ioctl(2), open(2), pipe(2)
READ-2 Printed 5/10/85