read - read from file


#include <stdio_p.h>

int read(fildes, buf, nbyte);
FD fildes;
char *buf;
unsigned nbyte;


fildes is a file descriptor obtained from a open system call.

read attempts to ready 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 incremented by the number of bytes read.

Devices that are incapable of seeking always read from the current position. The value of a file pointer with such a file is undefined.

Upon successful completion, a read returns the number of bytes read and placed in the buffer. The number of bytes read may be less than nbytes if the file is associated with a communication line (See tty(4P) and ioctl(2P) ), or the number of bytes left in the file is less than nbyte bytes. A value of 0 is returned when an end-of-file has been reached.

read will fail if fildes is not a valid file descriptor open for reading. [EBADF]


Upon successful completion a non-negative integer is returned indicating the number of bytes read. Otherwise, a -1 is returned and errno is set to indicate the error.


ioctl(2P) , open(2F) , tty(4P).