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