1WRITEV(3P) POSIX Programmer's Manual WRITEV(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 writev — write a vector
14
16 #include <sys/uio.h>
17
18 ssize_t writev(int fildes, const struct iovec *iov, int iovcnt);
19
21 The writev() function shall be equivalent to write(), except as
22 described below. The writev() function shall gather output data from
23 the iovcnt buffers specified by the members of the iov array: iov[0],
24 iov[1], ..., iov[iovcnt−1]. The iovcnt argument is valid if greater
25 than 0 and less than or equal to {IOV_MAX}, as defined in <limits.h>.
26
27 Each iovec entry specifies the base address and length of an area in
28 memory from which data should be written. The writev() function shall
29 always write a complete area before proceeding to the next.
30
31 If fildes refers to a regular file and all of the iov_len members in
32 the array pointed to by iov are 0, writev() shall return 0 and have no
33 other effect. For other file types, the behavior is unspecified.
34
35 If the sum of the iov_len values is greater than {SSIZE_MAX}, the oper‐
36 ation shall fail and no data shall be transferred.
37
39 Upon successful completion, writev() shall return the number of bytes
40 actually written. Otherwise, it shall return a value of −1, the file-
41 pointer shall remain unchanged, and errno shall be set to indicate an
42 error.
43
45 Refer to write().
46
47 In addition, the writev() function shall fail if:
48
49 EINVAL The sum of the iov_len values in the iov array would overflow an
50 ssize_t.
51
52 The writev() function may fail and set errno to:
53
54 EINVAL The iovcnt argument was less than or equal to 0, or greater than
55 {IOV_MAX}.
56
57 The following sections are informative.
58
60 Writing Data from an Array
61 The following example writes data from the buffers specified by members
62 of the iov array to the file associated with the file descriptor fd.
63
64 #include <sys/types.h>
65 #include <sys/uio.h>
66 #include <unistd.h>
67 ...
68 ssize_t bytes_written;
69 int fd;
70 char *buf0 = "short string\n";
71 char *buf1 = "This is a longer string\n";
72 char *buf2 = "This is the longest string in this example\n";
73 int iovcnt;
74 struct iovec iov[3];
75
76 iov[0].iov_base = buf0;
77 iov[0].iov_len = strlen(buf0);
78 iov[1].iov_base = buf1;
79 iov[1].iov_len = strlen(buf1);
80 iov[2].iov_base = buf2;
81 iov[2].iov_len = strlen(buf2);
82 ...
83 iovcnt = sizeof(iov) / sizeof(struct iovec);
84
85 bytes_written = writev(fd, iov, iovcnt);
86 ...
87
89 None.
90
92 Refer to write().
93
95 None.
96
98 readv(), write()
99
100 The Base Definitions volume of POSIX.1‐2008, <limits.h>, <sys_uio.h>
101
103 Portions of this text are reprinted and reproduced in electronic form
104 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
105 -- Portable Operating System Interface (POSIX), The Open Group Base
106 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
107 cal and Electronics Engineers, Inc and The Open Group. (This is
108 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
109 event of any discrepancy between this version and the original IEEE and
110 The Open Group Standard, the original IEEE and The Open Group Standard
111 is the referee document. The original Standard can be obtained online
112 at http://www.unix.org/online.html .
113
114 Any typographical or formatting errors that appear in this page are
115 most likely to have been introduced during the conversion of the source
116 files to man page format. To report such errors, see https://www.ker‐
117 nel.org/doc/man-pages/reporting_bugs.html .
118
119
120
121IEEE/The Open Group 2013 WRITEV(3P)