Nios® V Processor Software Developer Handbook

ID 743810
Date 10/12/2024
Public
Document Table of Contents

16.1.1.70. read()

Prototype

int read(int fd, void *ptr, size_t len)

Commonly Called By

C/C++ programs

Device drivers

Thread-safe

See description.

Available from ISR

No.

Include

<unistd.h>

Description

The read() function reads a block of data from a file or device. read() is wrapper function that passes control directly to the read() function registered for the device driver associated with the open file descriptor fd. The input argument, ptr, is the location to place the data read and len is the length of the data to read in bytes.

Calls to read() are thread-safe only if the implementation of read() provided by the driver that is manipulated is thread-safe.

Valid values for the fd parameter are: stdout, stdin, and stderr, or any value returned from a call to open().

Return

The return argument is the number of bytes read, which might be less than the requested length

The return value is –1 upon an error. In the event of an error, errno is set to indicate the cause.