read.2 (2010 09)

r
read(2) read(2)
NAME
read, readv, pread - read from file
SYNOPSIS
#include <unistd.h>
ssize_t read(int fildes, void *buf, size_t nbyte);
ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset);
#include <sys/uio.h>
ssize_t readv(int fildes, const struct iovec *iov, int iovcnt);
DESCRIPTION
The read() function attempts to read nbyte bytes from the file associated with the open file descriptor,
fildes, into the buffer pointed to by buf.
If nbyte is 0,
read() will return 0 and have no other results.
On files that support seeking (for example, a regular file), the
read() starts at a position in the file
given by the file offset associated with fildes . The file offset is incremented by the number of bytes actu-
ally read.
Files that do not support seeking, for example, terminals, always read from the current position. The
value of a file offset associated with such a file is undefined.
No data transfer will occur past the current end- of-file. If the starting position is at or after the
end-of-file, 0 will be returned. If the file refers to a device special file, the result of subsequent
read()
requests is implementation-dependent.
If the value of nbyte is greater than
{SSIZE_MAX} the result is implementation-dependent.
When attempting to read from an empty pipe (or FIFO):
If no process has the pipe open for writing, the read returns a 0.
If some process has the pipe open for writing and O_NONBLOCK is set, the read returns 1 and
errno is set to [EAGAIN].
If
O_NDELAY is set, the read returns a 0.
If some process has the pipe open for writing and
O_NDELAY and O_NONBLOCK are clear, the
read blocks until data is written to the file or the file is no longer open for writing.
When attempting to read a file (other than a pipe or FIFO) that supports non-blocking reads and has no
data currently available:
If
O_NONBLOCK is set, read() will return a 1 and set errno to [EAGAIN].
If
O_NONBLOCK is clear, read() will block until some data becomes available.
The use of the
O_NONBLOCK flag has no effect if there is some data available.
When attempting to read from a regular file with enforcement-mode file and record locking set (see
chmod(2)), and the segment of the file to be read is blocked by a write lock owned by another process, the
behavior is determined by the
O_NDELAY and O_NONBLOCK file status flags:
If
O_NDELAY or O_NONBLOCK is set, read() returns 1 and errno is set to [EAGAIN.]
If
O_NDELAY and O_NONBLOCK are clear, read() does not return until the blocking write
lock is removed.
When attempting to read a file associated with a tty that has no data currently available:
If
O_NDELAY is set, the read returns 0.
If
O_NDELAY and O_NONBLOCK are clear, the read blocks until data becomes available.
The
read() function reads data previously written to a file. If any portion of a regular file prior to the
end-of-file has not been written, read() returns bytes with value 0. For example, lseek() allows the
file offset to be set beyond the end of existing data in the file. If data is later written at this point, subse-
quent reads in the gap between the previous end of data and the newly written data will return bytes
with value 0 until data is written into the gap.
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (4 pages)