read

OS/161 Reference Manual

Name

read - read data from file

Library

Standard C Library (libc, -lc)

Synopsis

#include <unistd.h>

int
read(int fd, void *buf, size_t buflen);

Description

read reads up to buflen bytes from the file specified by fd, at the location in the file specified by the current seek position of the file, and stores them in the space pointed to by buf. The file must be open for reading.

The current seek position of the file is advanced by the number of bytes read.

Each read (or write) operation is atomic relative to other I/O to the same file.

Return Values

The count of bytes read is returned. This count should be positive. A return value of 0 should be construed as signifying end-of-file. On error, read returns -1 and sets errno to a suitable error code for the error condition encountered.

Note that in some cases, particularly on devices, fewer than buflen (but greater than zero) bytes may be returned. This depends on circumstances and does not necessarily signify end-of-file.

Errors

The following error codes should be returned under the conditions given. Other error codes may be returned for other errors not mentioned here.
  
EBADF fd is not a valid file descriptor, or was not opened for reading.
EFAULT Part or all of the address space pointed to by buf is invalid.
EIO A hardware I/O error occurred reading the data.