RTEMS 4.8.0 On-Line Library
Input and Output Primitives Manager read - Reads from a file.
RTEMS POSIX API User's Guide
5.4.5: read - Reads from a file.
CALLING SEQUENCE:
-
#include <unistd.h>
int read(
int fildes,
void *buf,
unsigned int nbyte
);
STATUS CODES:
On error, this routine returns -1 and sets errno
to one of
the following:
- EAGAIN
-
The O_NONBLOCK flag is set for a file descriptor and the process
would be delayed in the I/O operation.
- EBADF
-
Invalid file descriptor
- EINTR
-
Function was interrupted by a signal.
- EIO
-
Input or output error
DESCRIPTION:
The read()
function reads nbyte
bytes from the file
associated with fildes
into the buffer pointed to by buf
.
The read()
function returns the number of bytes actually read
and placed in the buffer. This will be less than nbyte
if:
- The number of bytes left in the file is less than
nbyte
.
- The
read()
request was interrupted by a signal.
- The file is a pipe or FIFO or special file with less than
nbytes
immediately available for reading.
When attempting to read from any empty pipe or FIFO:
- If no process has the pipe open for writing, zero is returned to
indicate end-of-file.
- If some process has the pipe open for writing and O_NONBLOCK is set,
-1 is returned and
errno
is set to EAGAIN.
- If some process has the pipe open for writing and O_NONBLOCK is clear,
read()
waits for some data to be written or the pipe to be closed.
When attempting to read from a file other than a pipe or FIFO and no data
is available.
- If O_NONBLOCK is set, -1 is returned and
errno
is set to EAGAIN.
- If O_NONBLOCK is clear,
read()
waits for some data to become
available.
- The O_NONBLOCK flag is ignored if data is available.
NOTES:
NONE
RTEMS POSIX API User's Guide
Copyright © 1988-2007OAR Corporation