fix copyright and condition notice for new sccs include
[unix-history] / usr / src / lib / libc / sys / write.2
CommitLineData
60792775
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
15fa213a 5.\" @(#)write.2 6.5 (Berkeley) %G%
60792775 6.\"
d341f19b 7.TH WRITE 2 ""
60792775
KM
8.UC 4
9.SH NAME
d1c0365c 10write, writev \- write output
60792775
KM
11.SH SYNOPSIS
12.nf
e35a5c92 13.ft B
d1c0365c
JL
14cc = write(d, buf, nbytes)
15int cc, d;
e35a5c92
KM
16char *buf;
17int nbytes;
18.PP
19.ft B
20#include <sys/types.h>
21#include <sys/uio.h>
22.PP
23.ft B
d1c0365c
JL
24cc = writev(d, iov, iovcnt)
25int cc, d;
e35a5c92 26struct iovec *iov;
d1c0365c 27int iovcnt;
60792775
KM
28.fi
29.SH DESCRIPTION
e35a5c92
KM
30.I Write
31attempts to write
60792775 32.I nbytes
e35a5c92
KM
33of data to the object referenced by the descriptor
34.I d
35from the buffer pointed to by
36.IR buf .
37.I Writev
38performs the same action, but gathers the output data
d1c0365c
JL
39from the
40.I iovcnt
41buffers specified by the members of the
42.I iov
43array: iov[0], iov[1], ..., iov[iovcnt\|\-\|1].
44.PP
45For
46.IR writev ,
47the
48.I iovec
49structure is defined as
50.PP
51.nf
52.RS
53.DT
54struct iovec {
55 caddr_t iov_base;
56 int iov_len;
57};
58.RE
59.fi
60.PP
61Each
62.I iovec
63entry specifies the base address and length of an area
64in memory from which data should be written.
65.I Writev
66will always write a complete area before proceeding
67to the next.
60792775 68.PP
e35a5c92
KM
69On objects capable of seeking, the \fIwrite\fP starts at a position
70given by the pointer associated with
71.IR d ,
72see
73.IR lseek (2).
74Upon return from
75.IR write ,
76the pointer is incremented by the number of bytes actually written.
60792775 77.PP
e35a5c92
KM
78Objects that are not capable of seeking always write from the current
79position. The value of the pointer associated with such an object
80is undefined.
60792775 81.PP
e35a5c92 82If the real user is not the super-user, then
60792775
KM
83.I write
84clears the set-user-id bit on a file.
85This prevents penetration of system security
86by a user who
e35a5c92 87\*(lqcaptures\*(rq a writable set-user-id file
60792775 88owned by the super-user.
15fa213a
MK
89.PP
90When using non-blocking I/O on objects such as sockets that are subject
91to flow control,
92.I write
93and
94.I writev
95may write fewer bytes than requested;
96the return value must be noted,
97and the remainder of the operation should be retried when possible.
e35a5c92 98.SH "RETURN VALUE
d1c0365c
JL
99Upon successful completion the number of bytes actually written
100is returned. Otherwise a \-1 is returned and the global variable
e35a5c92
KM
101.I errno
102is set to indicate the error.
103.SH ERRORS
104.I Write
d1c0365c
JL
105and
106.I writev
e35a5c92
KM
107will fail and the file pointer will remain unchanged if one or more
108of the following are true:
109.TP 15
110[EBADF]
111\fID\fP is not a valid descriptor open for writing.
112.TP 15
113[EPIPE]
114An attempt is made to write to a pipe that is not open
115for reading by any process.
116.TP 15
117[EPIPE]
118An attempt is made to write to a socket of type SOCK_STREAM
eff6446c 119that is not connected to a peer socket.
e35a5c92
KM
120.TP 15
121[EFBIG]
122An attempt was made to write a file that exceeds the process's
123file size limit or the maximum file size.
124.TP 15
125[EFAULT]
126Part of \fIiov\fP or data to be written to the file
127points outside the process's allocated address space.
fd690c8b 128.TP 15
d1c0365c
JL
129[EINVAL]
130The pointer associated with
131.I d
132was negative.
133.TP 15
fd690c8b
KM
134[ENOSPC]
135There is no free space remaining on the file system
136containing the file.
137.TP 15
138[EDQUOT]
139The user's quota of disk blocks on the file system
140containing the file has been exhausted.
141.TP 15
142[EIO]
143An I/O error occurred while reading from or writing to the file system.
15fa213a
MK
144.TP 15
145[EWOULDBLOCK]
146The file was marked for non-blocking I/O,
147and no data could be written immediately.
d1c0365c
JL
148.PP
149In addition,
150.I writev
151may return one of the following errors:
152.TP 15
153[EINVAL]
154.I Iovcnt
155was less than or equal to 0, or greater than 16.
156.TP 15
157[EINVAL]
158One of the
159.I iov_len
160values in the
161.I iov
162array was negative.
163.TP 15
164[EINVAL]
165The sum of the
166.I iov_len
167values in the
168.I iov
169array overflowed a 32-bit integer.
60792775 170.SH "SEE ALSO"
15fa213a 171fcntl(2), lseek(2), open(2), pipe(2), select(2)