.TH WRITE 2 "27 July 1983" .UC 4 .SH NAME write, writev \- write on a file .SH SYNOPSIS .nf .ft B write(d, buf, nbytes) int d; char *buf; int nbytes; .PP .ft B #include <sys/types.h> #include <sys/uio.h> .PP .ft B writev(d, iov, ioveclen) int d; struct iovec *iov; int ioveclen; .fi .SH DESCRIPTION .I Write attempts to write .I nbytes of data to the object referenced by the descriptor .I d from the buffer pointed to by .IR buf . .I Writev performs the same action, but gathers the output data from the \fIiovlen\fP buffers specified by the members of the \fIiovec\fP array: iov[0], iov[1], etc. .PP On objects capable of seeking, the \fIwrite\fP starts at a position given by the pointer associated with .IR d , see .IR lseek (2). Upon return from .IR write , the pointer is incremented by the number of bytes actually written. .PP 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. .PP If the real user is not the super-user, then .I write clears the set-user-id bit on a file. This prevents penetration of system security by a user who \*(lqcaptures\*(rq a writable set-user-id file owned by the super-user. .SH "RETURN VALUE Upon successful completion the number of bytes actually writen is returned. Otherwise a \-1 is returned and .I errno is set to indicate the error. .SH ERRORS .I Write will fail and the file pointer will remain unchanged if one or more of the following are true: .TP 15 [EBADF] \fID\fP is not a valid descriptor open for writing. .TP 15 [EPIPE] An attempt is made to write to a pipe that is not open for reading by any process. .TP 15 [EPIPE] An attempt is made to write to a socket of type SOCK_STREAM which is not connected to a peer socket. .TP 15 [EFBIG] An attempt was made to write a file that exceeds the process's file size limit or the maximum file size. .TP 15 [EFAULT] Part of \fIiov\fP or data to be written to the file points outside the process's allocated address space. .SH "SEE ALSO" lseek(2), open(2), pipe(2)