WRITE(2) BSD Programmer's Manual WRITE(2)
w
\bwr
\bri
\bit
\bte
\be, w
\bwr
\bri
\bit
\bte
\bev
\bv - write output
S
\bSY
\bYN
\bNO
\bOP
\bPS
\bSI
\bIS
\bS
#
\b#i
\bin
\bnc
\bcl
\blu
\bud
\bde
\be <
\b<u
\bun
\bni
\bis
\bst
\btd
\bd.
\b.h
\bh>
\b>
#
\b#i
\bin
\bnc
\bcl
\blu
\bud
\bde
\be <
\b<s
\bsy
\bys
\bs/
\b/t
\bty
\byp
\bpe
\bes
\bs.
\b.h
\bh>
\b>
#
\b#i
\bin
\bnc
\bcl
\blu
\bud
\bde
\be <
\b<s
\bsy
\bys
\bs/
\b/u
\bui
\bio
\bo.
\b.h
\bh>
\b>
_
\bs_
\bs_
\bi_
\bz_
\be_
\b__
\bt
w
\bwr
\bri
\bit
\bte
\be(_
\bi_
\bn_
\bt _
\bd, _
\bc_
\bo_
\bn_
\bs_
\bt _
\bv_
\bo_
\bi_
\bd _
\b*_
\bb_
\bu_
\bf, _
\bs_
\bi_
\bz_
\be_
\b__
\bt _
\bn_
\bb_
\by_
\bt_
\be_
\bs);
w
\bwr
\bri
\bit
\bte
\bev
\bv(_
\bi_
\bn_
\bt _
\bd, _
\bs_
\bt_
\br_
\bu_
\bc_
\bt _
\bi_
\bo_
\bv_
\be_
\bc _
\b*_
\bi_
\bo_
\bv, _
\bi_
\bn_
\bt _
\bi_
\bo_
\bv_
\bc_
\bn_
\bt);
D
\bDE
\bES
\bSC
\bCR
\bRI
\bIP
\bPT
\bTI
\bIO
\bON
\bN
W
\bWr
\bri
\bit
\bte
\be() attempts to write _
\bn_
\bb_
\by_
\bt_
\be_
\bs of data to the object referenced by the
descriptor _
\bd from the buffer pointed to by _
\bb_
\bu_
\bf. W
\bWr
\bri
\bit
\bte
\bev
\bv() performs the
same action, but gathers the output data from the _
\bi_
\bo_
\bv_
\bc_
\bn_
\bt buffers speci-
fied by the members of the _
\bi_
\bo_
\bv array: iov[0], iov[1], ..., iov[iovcnt-1].
For w
\bwr
\bri
\bit
\bte
\bev
\bv(), the _
\bi_
\bo_
\bv_
\be_
\bc structure is defined as:
Each _
\bi_
\bo_
\bv_
\be_
\bc entry specifies the base address and length of an area in mem-
ory from which data should be written. W
\bWr
\bri
\bit
\bte
\bev
\bv() will always write a com-
plete area before proceeding to the next.
On objects capable of seeking, the w
\bwr
\bri
\bit
\bte
\be() starts at a position given by
the pointer associated with _
\bd, see lseek(2). Upon return from w
\bwr
\bri
\bit
\bte
\be(),
the pointer is incremented by the number of bytes which were written.
Objects that are not capable of seeking always write from the current po-
sition. The value of the pointer associated with such an object is unde-
If the real user is not the super-user, then w
\bwr
\bri
\bit
\bte
\be() 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 super-user.
When using non-blocking I/O on objects such as sockets that are subject
to flow control, w
\bwr
\bri
\bit
\bte
\be() and w
\bwr
\bri
\bit
\bte
\bev
\bv() may write fewer bytes than request-
ed; the return value must be noted, and the remainder of the operation
should be retried when possible.
R
\bRE
\bET
\bTU
\bUR
\bRN
\bN V
\bVA
\bAL
\bLU
\bUE
\bES
\bS
Upon successful completion the number of bytes which were written is re-
turned. Otherwise a -1 is returned and the global variable _
\be_
\br_
\br_
\bn_
\bo is set
W
\bWr
\bri
\bit
\bte
\be() and w
\bwr
\bri
\bit
\bte
\bev
\bv() will fail and the file pointer will remain unchanged
[EBADF] _
\bD is not a valid descriptor open for writing.
[EPIPE] An attempt is made to write to a pipe that is not open for
[EPIPE] An attempt is made to write to a socket of type that is not
connected to a peer socket.
[EFBIG] An attempt was made to write a file that exceeds the pro-
cess's file size limit or the maximum file size.
[EFAULT] Part of _
\bi_
\bo_
\bv or data to be written to the file points out-
side the process's allocated address space.
[EINVAL] The pointer associated with _
\bd was negative.
[ENOSPC] There is no free space remaining on the file system con-
[EDQUOT] The user's quota of disk blocks on the file system contain-
ing the file has been exhausted.
[EIO] An I/O error occurred while reading from or writing to the
[EAGAIN] The file was marked for non-blocking I/O, and no data could
In addition, w
\bwr
\bri
\bit
\bte
\bev
\bv() may return one of the following errors:
[EINVAL] _
\bI_
\bo_
\bv_
\bc_
\bn_
\bt was less than or equal to 0, or greater than 16.
[EINVAL] One of the _
\bi_
\bo_
\bv_
\b__
\bl_
\be_
\bn values in the _
\bi_
\bo_
\bv array was negative.
[EINVAL] The sum of the _
\bi_
\bo_
\bv_
\b__
\bl_
\be_
\bn values in the _
\bi_
\bo_
\bv array overflowed a
S
\bSE
\bEE
\bE A
\bAL
\bLS
\bSO
\bO
fcntl(2), lseek(2), open(2), pipe(2), select(2)
S
\bST
\bTA
\bAN
\bND
\bDA
\bAR
\bRD
\bDS
\bS
W
\bWr
\bri
\bit
\bte
\be() is expected to conform to IEEE Std 1003.1-1988 (``POSIX'').
H
\bHI
\bIS
\bST
\bTO
\bOR
\bRY
\bY
The w
\bwr
\bri
\bit
\bte
\bev
\bv() function call appeared in 4.2BSD. A w
\bwr
\bri
\bit
\bte
\be function call ap-
peared in Version 6 AT&T UNIX.
4th Berkeley Distribution June 4, 1993 2