Function write

Top 

Declaration:

int write(long handle, void buf[], int len);

Description

Writes to a file.

write writes the buffer of data to the file or device specified by handle. The handle file handle is obtained from the creatopen, dup, or dup2 call.

This function attempts to write bytes from the buffer pointed to by buf to the file associated with handle. Except for the case, when write is used to write to a text file, the amount of bytes written to the file will be no more than the amount requested. On text files, when write sees a linefeed (LF) character, it outputs a CR/LF pair.

If the amount of bytes actually written is less than that requested, the condition should be considered an error and probably indicates a full disk. For disks or disk files, the writing always proceeds from the current file pointer. For devices, bytes are sent directly to the device.

Returned Value

write returns the number of bytes written. A write to a text file does not count the generated carriage returns. In case of error, write returns -1 and sets the errno global variable to one of the following values:

EACCES       Permission denied

EBADF        Bad file number