Write bytes to a file
ssize_t writev( int fildes,
const iov_t* iov,
int nparts );
- The file descriptor for the file you want to write in.
- An array of iov_t objects that contain the data that you want to write.
The combined size (i.e., the sum of the length values) of the objects must not exceed
INT_MAX - sizeof(io_write_t) (see <limits.h>),
or the function fails and sets errno.
If the size is greater than INT_MAX - sizeof(io_write_t) but less than or equal to
INT_MAX, errno is set to EOVERFLOW.
If the size is greater than INT_MAX, errno is set to EINVAL.
- The number of entries in the iov array.
The maximum number of entries is UIO_MAXIOV.
Use the -l c option to
to link against this library.
This library is usually included automatically.
The writev() function performs the same action as
but gathers the output data from the nparts
buffers specified by the members of the iov array:
iov, iov, …, iov[nparts-1].
For writev(), the iov_t structure contains the
- Base address of a memory area from which data should be written.
- The length of the memory area.
The writev() function always writes a complete area before proceeding to the
||Note that writev() ignores advisory locks that may
have been set by the fcntl()
If writev() is interrupted by a signal before it has written any
data, it returns -1 and sets errno to
EINTR. However, if writev() is interrupted by a signal
after it has successfully written some data, it will return the number
of bytes written.
For more details, see the
The number of bytes written, or -1 if an error occurs
- The O_NONBLOCK flag is set for the file descriptor, and
the process would be delayed in the write operation.
- The file descriptor, fildes, isn't a valid file descriptor
open for writing.
- The file is a regular file, where nbytes is greater than 0, and
the starting position is greater than or equal to the offset maximum
associated with the file.
- The write operation was interrupted by a signal, and either no data
was transferred, or the resource manager responsible for that file doesn't
report partial transfers.
- The nparts argument is less than or equal to 0, or greater than
UIO_MAXIOV. Or, an attempt was made to write a number bytes that exceeds
the allowable limit.
- A physical I/O error occurred (for example, a bad block on a disk). The
precise meaning is device-dependent.
- There is no free space remaining on the device containing the file.
- The write() function isn't implemented for the filesystem specified
- An attempt was made to write a number of bytes that when added to the size of the
write message structure exceeds the allowable limit.
- An attempt was made to write to a pipe (or FIFO) that isn't open for
reading by any process. A SIGPIPE signal is also sent to
POSIX 1003.1 XSI