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
12 writev - write a vector
13
15 #include <sys/uio.h>
16
17 ssize_t writev(int fildes, const struct iovec *iov, int iovcnt);
18
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
53 The writev() function may fail and set errno to:
54
55 EINVAL The iovcnt argument was less than or equal to 0, or greater than
56 {IOV_MAX}.
57
58
59 The following sections are informative.
60
62 Writing Data from an Array
63 The following example writes data from the buffers specified by members
64 of the iov array to the file associated with the file descriptor fd.
65
66
67 #include <sys/types.h>
68 #include <sys/uio.h>
69 #include <unistd.h>
70 ...
71 ssize_t bytes_written;
72 int fd;
73 char *buf0 = "short string\n";
74 char *buf1 = "This is a longer string\n";
75 char *buf2 = "This is the longest string in this example\n";
76 int iovcnt;
77 struct iovec iov[3];
78
79
80 iov[0].iov_base = buf0;
81 iov[0].iov_len = strlen(buf0);
82 iov[1].iov_base = buf1;
83 iov[1].iov_len = strlen(buf1);
84 iov[2].iov_base = buf2;
85 iov[2].iov_len = strlen(buf2);
86 ...
87 iovcnt = sizeof(iov) / sizeof(struct iovec);
88
89
90 bytes_written = writev(fd, iov, iovcnt);
91 ...
92
94 None.
95
97 Refer to write().
98
100 None.
101
103 readv(), write(), the Base Definitions volume of IEEE Std 1003.1-2001,
104 <limits.h>, <sys/uio.h>
105
107 Portions of this text are reprinted and reproduced in electronic form
108 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
109 -- Portable Operating System Interface (POSIX), The Open Group Base
110 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
111 Electrical and Electronics Engineers, Inc and The Open Group. In the
112 event of any discrepancy between this version and the original IEEE and
113 The Open Group Standard, the original IEEE and The Open Group Standard
114 is the referee document. The original Standard can be obtained online
115 at http://www.opengroup.org/unix/online.html .
116
117
118
119IEEE/The Open Group 2003 WRITEV(3P)