1WRITE(2) System Calls Manual WRITE(2)
2
3
4
6 write, writev - write output
7
9 cc = write(d, buf, nbytes)
10 int cc, d;
11 char *buf;
12 unsigned short nbytes;
13
14 #include <sys/types.h>
15 #include <sys/uio.h>
16
17 cc = writev(d, iov, iovcnt)
18 int cc, d;
19 struct iovec *iov;
20 int iovcnt;
21
23 Write attempts to write nbytes of data to the object referenced by the
24 descriptor d from the buffer pointed to by buf. Writev performs the
25 same action, but gathers the output data from the iovcnt buffers speci‐
26 fied by the members of the iov array: iov[0], iov[1], ...,
27 iov[iovcnt-1].
28
29 For writev, the iovec structure is defined as
30
31 struct iovec {
32 caddr_t iov_base;
33 u_short iov_len;
34 };
35
36 Each iovec entry specifies the base address and length of an area in
37 memory from which data should be written. Writev will always write a
38 complete area before proceeding to the next.
39
40 On objects capable of seeking, the write starts at a position given by
41 the pointer associated with d, see lseek(2). Upon return from write,
42 the pointer is incremented by the number of bytes actually written.
43
44 Objects that are not capable of seeking always write from the current
45 position. The value of the pointer associated with such an object is
46 undefined.
47
48 If the real user is not the super-user, then write clears the set-user-
49 id bit on a file. This prevents penetration of system security by a
50 user who “captures” a writable set-user-id file owned by the super-
51 user.
52
53 When using non-blocking I/O on objects such as sockets that are subject
54 to flow control, write and writev may write fewer bytes than requested;
55 the return value must be noted, and the remainder of the operation
56 should be retried when possible.
57
59 Upon successful completion the number of bytes actually written is
60 returned. Otherwise a -1 is returned and the global variable errno is
61 set to indicate the error.
62
64 Write and writev will fail and the file pointer will remain unchanged
65 if one or more of the following are true:
66
67 [EBADF] D is not a valid descriptor open for writing.
68
69 [EPIPE] An attempt is made to write to a pipe that is not open
70 for reading by any process.
71
72 [EPIPE] An attempt is made to write to a socket of type
73 SOCK_STREAM that is not connected to a peer socket.
74
75 [EFBIG] An attempt was made to write a file that exceeds the
76 process's file size limit or the maximum file size.
77
78 [EFAULT] Part of iov or data to be written to the file points
79 outside the process's allocated address space.
80
81 [EINVAL] The pointer associated with d was negative.
82
83 [ENOSPC] There is no free space remaining on the file system con‐
84 taining the file.
85
86 [EDQUOT] The user's quota of disk blocks on the file system con‐
87 taining the file has been exhausted.
88
89 [EIO] An I/O error occurred while reading from or writing to
90 the file system.
91
92 [EWOULDBLOCK] The file was marked for non-blocking I/O, and no data
93 could be written immediately.
94
95 In addition, writev may return one of the following errors:
96
97 [EINVAL] Iovcnt was less than or equal to 0, or greater than 16.
98
99 [EINVAL] The sum of the iov_len values in the iov array over‐
100 flowed a short.
101
103 fcntl(2), lseek(2), open(2), pipe(2), select(2)
104
105
106
1074th Berkeley Distribution August 1, 1987 WRITE(2)