manual page first distributed with 4.2BSD
[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.\"
d341f19b 5.\" @(#)write.2 6.1 (Berkeley) %G%
60792775 6.\"
d341f19b 7.TH WRITE 2 ""
60792775
KM
8.UC 4
9.SH NAME
e35a5c92 10write, writev \- write on a file
60792775
KM
11.SH SYNOPSIS
12.nf
e35a5c92
KM
13.ft B
14write(d, buf, nbytes)
15int d;
16char *buf;
17int nbytes;
18.PP
19.ft B
20#include <sys/types.h>
21#include <sys/uio.h>
22.PP
23.ft B
24writev(d, iov, ioveclen)
25int d;
26struct iovec *iov;
27int ioveclen;
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
39from the \fIiovlen\fP buffers specified by the members
40of the \fIiovec\fP array: iov[0], iov[1], etc.
60792775 41.PP
e35a5c92
KM
42On objects capable of seeking, the \fIwrite\fP starts at a position
43given by the pointer associated with
44.IR d ,
45see
46.IR lseek (2).
47Upon return from
48.IR write ,
49the pointer is incremented by the number of bytes actually written.
60792775 50.PP
e35a5c92
KM
51Objects that are not capable of seeking always write from the current
52position. The value of the pointer associated with such an object
53is undefined.
60792775 54.PP
e35a5c92 55If the real user is not the super-user, then
60792775
KM
56.I write
57clears the set-user-id bit on a file.
58This prevents penetration of system security
59by a user who
e35a5c92 60\*(lqcaptures\*(rq a writable set-user-id file
60792775 61owned by the super-user.
e35a5c92
KM
62.SH "RETURN VALUE
63Upon successful completion the number of bytes actually writen
64is returned. Otherwise a \-1 is returned and
65.I errno
66is set to indicate the error.
67.SH ERRORS
68.I Write
69will fail and the file pointer will remain unchanged if one or more
70of the following are true:
71.TP 15
72[EBADF]
73\fID\fP is not a valid descriptor open for writing.
74.TP 15
75[EPIPE]
76An attempt is made to write to a pipe that is not open
77for reading by any process.
78.TP 15
79[EPIPE]
80An attempt is made to write to a socket of type SOCK_STREAM
81which is not connected to a peer socket.
82.TP 15
83[EFBIG]
84An attempt was made to write a file that exceeds the process's
85file size limit or the maximum file size.
86.TP 15
87[EFAULT]
88Part of \fIiov\fP or data to be written to the file
89points outside the process's allocated address space.
60792775 90.SH "SEE ALSO"
e35a5c92 91lseek(2), open(2), pipe(2)