Changed 'caddr_t' to 'char *' -- 'caddr_t' isn't supposed to be visible
[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.\"
d1c0365c 5.\" @(#)write.2 6.4 (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.
e35a5c92 89.SH "RETURN VALUE
d1c0365c
JL
90Upon successful completion the number of bytes actually written
91is returned. Otherwise a \-1 is returned and the global variable
e35a5c92
KM
92.I errno
93is set to indicate the error.
94.SH ERRORS
95.I Write
d1c0365c
JL
96and
97.I writev
e35a5c92
KM
98will fail and the file pointer will remain unchanged if one or more
99of the following are true:
100.TP 15
101[EBADF]
102\fID\fP is not a valid descriptor open for writing.
103.TP 15
104[EPIPE]
105An attempt is made to write to a pipe that is not open
106for reading by any process.
107.TP 15
108[EPIPE]
109An attempt is made to write to a socket of type SOCK_STREAM
eff6446c 110that is not connected to a peer socket.
e35a5c92
KM
111.TP 15
112[EFBIG]
113An attempt was made to write a file that exceeds the process's
114file size limit or the maximum file size.
115.TP 15
116[EFAULT]
117Part of \fIiov\fP or data to be written to the file
118points outside the process's allocated address space.
fd690c8b 119.TP 15
d1c0365c
JL
120[EINVAL]
121The pointer associated with
122.I d
123was negative.
124.TP 15
fd690c8b
KM
125[ENOSPC]
126There is no free space remaining on the file system
127containing the file.
128.TP 15
129[EDQUOT]
130The user's quota of disk blocks on the file system
131containing the file has been exhausted.
132.TP 15
133[EIO]
134An I/O error occurred while reading from or writing to the file system.
d1c0365c
JL
135.PP
136In addition,
137.I writev
138may return one of the following errors:
139.TP 15
140[EINVAL]
141.I Iovcnt
142was less than or equal to 0, or greater than 16.
143.TP 15
144[EINVAL]
145One of the
146.I iov_len
147values in the
148.I iov
149array was negative.
150.TP 15
151[EINVAL]
152The sum of the
153.I iov_len
154values in the
155.I iov
156array overflowed a 32-bit integer.
60792775 157.SH "SEE ALSO"
e35a5c92 158lseek(2), open(2), pipe(2)