#include <sys/types.h> #include <sys/uio.h> int writev(int descriptor, struct iovec *io_vector[], int vector_length)
The writev() function is used to write data to a file or socket descriptor. writev() provides a way for the data that is going to be written to be stored in several different buffers (scatter/gather I/O).
Note: When the write completes successfully, the S_ISUID (set-user-ID) and S_ISGID (set-group-ID) bits of the file mode will be cleared. If the write is unsuccessful, the bits are undefined.
See write()--Write to Descriptor for more information related to writing to a descriptor.
struct iovec { void *iov_base; size_t iov_len; }
iov_base and iov_len are the only fields in iovec used by sockets. iov_base contains the pointer to a buffer and iov_len contains the buffer length. The rest of the fields are reserved.
No authorization is required.
value | writev() was successful. The value returned is the number of bytes actually written. |
-1 | writev() was not successful. The errno global variable is set to indicate the error. |
If writev() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
Error condition | Additional information |
---|---|
[EACCES] |
If you are accessing a remote file through the Network File System, update operations to file permissions at the server are not reflected at the client until updates to data that is stored locally by the Network File System take place. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.) Access to a remote file may also fail due to different mappings of user IDs (UID) or group IDs (GID) on the local and remote systems. If writing to a socket, this error code indicates one of the following:
|
[EAGAIN] | |
[EBADF] | |
[EBADFID] | |
[EBUSY] | |
[EDAMAGE] | |
[EFAULT] | |
[EFBIG] |
The size of the object would exceed the system allowed maximum size or the process soft file size limit. The file is a regular file, nbyte is greater than 0, and the starting offset is greater than or equal to 2 GB minus 2 bytes. |
[EINTR] | |
[EINVAL] |
For example, the file resides in a file system that does not support large files, and the starting offset exceeds 2GB minus 2 bytes. |
[EIO] | |
[EJRNDAMAGE] | |
[EJRNENTTOOLONG] | |
[EJRNINACTIVE] | |
[EJRNRCVSPC] | |
[ENEWJRN] | |
[ENEWJRNRCV] | |
[ENOMEM] | |
[ENOSPC] | |
[ENOTAVAIL] | |
[ENOTSAFE] | |
[ERESTART] | |
[ESTALE] |
If you are accessing a remote file through the Network File System, the file may have been deleted at the server. |
[ETRUNC] | |
[EUNKNOWN] |
When the descriptor refers to a socket, errno could indicate one of the following errors:
Error condition | Additional information |
---|---|
[ECONNREFUSED] |
This error code can only be returned on sockets that use a connectionless transport service. |
[EDESTADDRREQ] |
A destination address has not been associated with the socket pointed to by the fildes parameter. This error code can only be returned on sockets that use a connectionless transport service. |
[EHOSTDOWN] |
This error code can only be returned on sockets that use a connectionless transport service. |
[EHOSTUNREACH] |
This error code can only be returned on sockets that use a connectionless transport service. |
[EINTR] | |
[EMSGSIZE] |
The data to be sent could not be sent atomically because the size specified by nbyte is too large. |
[ENETDOWN] |
This error code can only be returned on sockets that use a connectionless transport service. |
[ENETUNREACH] |
This error code can only be returned on sockets that use a connectionless transport service. |
[ENOBUFS] | |
[ENOTCONN] |
This error code is returned only on sockets that use a connection-oriented transport service. |
[EPIPE] | |
[EUNATCH] | |
[EWOULDBLOCK] |
If interaction with a file server is required to access the object, errno could indicate one of the following errors:
Error condition | Additional information |
---|---|
[EADDRNOTAVAIL] | |
[ECONNABORTED] | |
[ECONNREFUSED] | |
[ECONNRESET] | |
[EHOSTDOWN] | |
[EHOSTUNREACH] | |
[ENETDOWN] | |
[ENETRESET] | |
[ENETUNREACH] | |
[ESTALE] |
If you are accessing a remote file through the Network File System, the file may have been deleted at the server. |
[ETIMEDOUT] | |
[EUNATCH] |
Message ID | Error Message Text |
---|---|
CPE3418 E | Possible APAR condition or hardware failure. |
CPF3CF2 E | Error(s) occurred during running of &1 API. |
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
CPFA081 E | Unable to set return value or error code. |
CPFA0D4 E | File system error occurred. Error number &1. |
writev() only works with sockets on which a connect() has been issued, since the call does not allow the caller to specify a destination address.
writev() is an atomic operation on sockets of type SOCK_DGRAM and SOCK_RAW in that it produces one packet of data every time it is issued. For example, a writev() to a datagram socket results in a single datagram.
To broadcast on an AF_INET socket, the socket option SO_BROADCAST must be set (with a setsockopt()).
To get the actual error, use getsockopt() with the SO_ERROR option, or perform an input operation (for example, read()).
For the file systems that do not support large files, writev() will return [EINVAL] if the starting offset exceeds 2GB minus 2 bytes, regardless of how the file was opened. For the file systems that do support large files, writev() will return [EFBIG] if the starting offset exceeds 2GB minus 2 bytes and the file was not opened for large file access.
The largest buffer size allowed is 16 megabytes. If a larger buffer is passed, the error EINVAL will be received.
When writing to files on volumes formatted in Universal Disk Format (UDF), byte locks on the range being written are ignored.
Using this function successfully on the dev/null or /dev/zero character special file results in a return value of the total number of bytes requested to be written. No data is written to the character special file. In addition, the change and modification times for the file are updated.
If the write exceeds the process soft file size limit, signal SIFXFSZ is issued.
Top | UNIX-Type APIs | APIs by category |