WRITE(2) COMMAND REFERENCE WRITE(2)
NAME
write, writev - write on a file
SYNOPSIS
cc = write(fd, buf, nbytes)
int cc;
int fd;
char *buf;
int nbytes;
#include <sys/types.h>
#include <sys/uio.h>
cc = writev(fd, iov, iovcnt)
int cc;
int fd;
struct iovec *iov;
int iovcnt;
DESCRIPTION
The write call attempts to write nbytes of data to the
object referenced by the descriptor fd from the buffer
pointed to by buf; writev performs the same action, but
gathers the output data from iovcnt buffers specified by the
members of the iovec array: iov[0], iov[1], ...,
iov[iovcnt-1].
The writev call is not supported for raw devices (for
example, raw disks, terminals) nor is it supported for a
file located on a remote host; both write and writev return
the number of bytes written in cc.
For writev, the iovec structure is defined in <sys/uio.h>
as:
struct iovec {
caddr_t iov_base;
int iov_len;
};
Each iovec entry specifies the base address and length of an
area in memory where data is gathered.
On objects capable of seeking, the write starts at a
position given by the pointer associated with fd, see
lseek(2). Upon return from write, the pointer is
incremented by the number of bytes actually 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.
Printed 4/6/89 1
WRITE(2) COMMAND REFERENCE WRITE(2)
If the real user is not the superuser, then write clears the
set-user-id bit on a file; this prevents penetration of
system security by a user who "captures" a writable set-
user-id file owned by the superuser.
DIAGNOSTICS
Calls write and writev fail and the file pointer remains
unchanged if one or more of the following are true:
[EBADF] Fd is not a valid descriptor open for writing.
[EPIPE] An attempt is made to write to a pipe that is
not open for reading by any process.
[EIO] An I/O error occurred while reading from or
writing to the file system.
[EPIPE] An attempt is made to write to a socket of type
SOCK_STREAM which is not connected to a peer
socket.
[EFBIG] An attempt is made to write a file that exceeds
the process's file size limit or the maximum
file size.
[EFAULT] Part of iov or data to be written to the file
points outside the process's allocated address
space.
[EMSGSIZE] Fd is a socket, and the message sent on it was
larger than the internal message buffer.
[ENOTCONN] Fd is a socket which is not connected.
[EDESTADDREQ]
Fd is a socket, and a required address was
omitted from the write request on the socket.
[EWOULDBLOCK]
Fd is in non-blocking mode, and the write would
cause a process block.
[ENOBUFS] Fd is a socket, and the system lacks sufficient
buffer space to do the write.
In addition, writev fails if one or more of the following
are true:
[EINVAL] One of the iov_len values in the iov array is
negative.
[EINVAL] The sum of the iov_len values in the iov array
Printed 4/6/89 2
WRITE(2) COMMAND REFERENCE WRITE(2)
overflows a 32 bit integer.
[EINVAL] Iovcnt is less than or equal to 0, or greater
than 16.
[ENXIO] A writev call was attempted on an unsupported
raw device.
RETURN VALUE
Upon successful completion the number of bytes written is
returned in cc. Otherwise a -1 is returned and errno is set
to indicate the error.
SEE ALSO
lseek(2), open(2), pipe(2), and read(2).
Printed 4/6/89 3
%%index%%
na:264,83;
sy:347,1899;
de:2246,1894;4476,282;
di:4758,2360;7454,306;
rv:7760,294;
se:8054,204;
%%index%%000000000129