write(), writev() - write output
#include <unistd.h>
ssize_t write (int d, const void *buf, size_t nbytes)
#include <sys/uio.h>
ssize_t writev (int d, const struct iovec *iov, int iovcnt)
The write(2) function attempts to write nbytes of data to the object referenced by the descriptor d from the buffer pointed to by buf. The function writev(2) performs the same action, but gathers the output data from the iovcnt buffers specified by the members of the iov array: iov[0], iov[1], ..., iov[iovcnt-1].
For writev(2), the iovec structure is defined as:
struct iovec {
void *iov_base;
size_t iov_len;
};
Each iovec entry specifies the base address and length of an area in memory from which data should be written. The writev(2) function will always write a complete area before proceeding to the next.
On objects capable of seeking, the write(2) starts at a position given by the pointer associated with d, (see lseek(2)). Upon return from write(2), the pointer is incremented by the number of bytes which were written.
Objects that are not capable of seeking always write from the current position. The value of the pointer associated with such an object is undefined.
When using non-blocking input/output (I/O) on objects such as sockets that are subject to flow control, write(2) and writev(2) can write fewer bytes than requested; the return value must be noted, and the remainder of the operation should be retried when possible.
Upon successful completion the number of bytes which were written is returned. Otherwise a -1 is returned and the global variable errno is set to indicate the error.
When calling the write(2) function on a file that is not a regular file with nbytes set to zero, the function returns 0.
When the nbytes argument exceeds {SSIZE_MAX}, the return value is truncated to type ssize_t.
The write(2) and writev(2) functions will fail and the file pointer will remain unchanged if:
In addition, writev(2) may return one of the following errors:
fcntl(2)
lseek(2)
open(2)
pipe(2)
select(2)