Write data to an open file descriptor.
Syntax
#include <unistd.h>
ssize_t write (int fd, const void *buffer, ssize_t nbytes);
Parameters
-
fd
The file descriptor to write data to.
-
buffer
A pointer to the buffer that contains the data.
-
nbytes
Maximum number of bytes to write.
Return Value
The return value is the number of bytes written if successful. Otherwise, the return value is negative and errno is set:
-
EBADF
Bad file descriptor.
Remarks
The number of bytes written may not be the same as the number of bytes specified in the third argument. Most drivers are implemented with non-blocking IO and will return zero (no bytes written) when there is no data available. Partial writes may also be possible depending on the driver.
For information on how to correctly use write
to write data to a driver, see
the appropriate driver documentation and examples. Files residing on disk can
be expected to write either nbytes
of data or an error, whatever occurs first.