Nios® V Processor Software Developer Handbook

ID 743810
Date 7/08/2024
Public
Document Table of Contents

16.1.1.71. write()

Prototype

int write(int fd, const void *ptr, size_t len)

Commonly Called By

C/C++ programs

newlib C library

Thread-safe

See description.

Available from ISR

No.

Include

<unistd.h>

Description

The write() function writes a block of data to a file or device. write() is wrapper function that passes control directly to the write() function registered for the device driver associated with the file descriptor fd. The input argument ptr is the data to write and len is the length of the data in bytes.

Calls to write() are thread-safe only if the implementation of write() 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 written, 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.