write - write on a file


#include <stdio_p.h>

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


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

write attempts to write nbyte bytes from the buffer pointed to by buf to the file associated with fildes.

On devices capable of seeking, the writing of data proceeds from the position in the file indicated by the file pointer. Upon returning from write, the file pointer is incremented by the number of bytes written.

On devices incapable of seeking, writing always takes place starting at the current position. The value of a file pointer associated with such a device is undefined.

write will fail and the file pointer will remain unchaged if one or more of the following are true:

If the file being written is a FIFO on the host, no partial writes will be permitted. Thus, the write will fail if a write of nbyte bytes would exceed a limit.


Upon successful completion the number of bytes written is returned. Otherwise, -1 is returned and errno is set to indicate the error.


lseek(2P) , open(2F)