1WRITEV(3P)                 POSIX Programmer's Manual                WRITEV(3P)
2
3
4

PROLOG

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

NAME

12       writev — write a vector
13

SYNOPSIS

15       #include <sys/uio.h>
16
17       ssize_t writev(int fildes, const struct iovec *iov, int iovcnt);
18

DESCRIPTION

20       The writev()  function  shall  be  equivalent  to  write(),  except  as
21       described  below.  The  writev() function shall gather output data from
22       the iovcnt buffers specified by the members of the iov  array:  iov[0],
23       iov[1],  ...,  iov[iovcnt-1].   The iovcnt argument is valid if greater
24       than 0 and less than or equal to {IOV_MAX}, as defined in <limits.h>.
25
26       Each iovec entry specifies the base address and length of  an  area  in
27       memory  from  which data should be written. The writev() function shall
28       always write a complete area before proceeding to the next.
29
30       If fildes refers to a regular file and all of the  iov_len  members  in
31       the  array pointed to by iov are 0, writev() shall return 0 and have no
32       other effect. For other file types, the behavior is unspecified.
33
34       If the sum of the iov_len values is greater than {SSIZE_MAX}, the oper‐
35       ation shall fail and no data shall be transferred.
36

RETURN VALUE

38       Upon  successful  completion, writev() shall return the number of bytes
39       actually written. Otherwise, it shall return a value of -1,  the  file-
40       pointer  shall  remain unchanged, and errno shall be set to indicate an
41       error.
42

ERRORS

44       Refer to write().
45
46       In addition, the writev() function shall fail if:
47
48       EINVAL The sum of the iov_len values in the iov array would overflow an
49              ssize_t.
50
51       The writev() function may fail and set errno to:
52
53       EINVAL The iovcnt argument was less than or equal to 0, or greater than
54              {IOV_MAX}.
55
56       The following sections are informative.
57

EXAMPLES

59   Writing Data from an Array
60       The following example writes data from the buffers specified by members
61       of the iov array to the file associated with the file descriptor fd.
62
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

APPLICATION USAGE

89       None.
90

RATIONALE

92       Refer to write().
93

FUTURE DIRECTIONS

95       None.
96

SEE ALSO

98       readv(), write()
99
100       The Base Definitions volume of POSIX.1‐2017, <limits.h>, <sys_uio.h>
101
103       Portions  of  this text are reprinted and reproduced in electronic form
104       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
105       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
106       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
107       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
108       event of any discrepancy between this version and the original IEEE and
109       The  Open Group Standard, the original IEEE and The Open Group Standard
110       is the referee document. The original Standard can be  obtained  online
111       at http://www.opengroup.org/unix/online.html .
112
113       Any  typographical  or  formatting  errors that appear in this page are
114       most likely to have been introduced during the conversion of the source
115       files  to  man page format. To report such errors, see https://www.ker
116       nel.org/doc/man-pages/reporting_bugs.html .
117
118
119
120IEEE/The Open Group                  2017                           WRITEV(3P)
Impressum