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

NAME

6       writev - write a vector
7

SYNOPSIS

9       #include <sys/uio.h>
10
11       ssize_t writev(int fildes, const struct iovec *iov, int iovcnt);
12
13

DESCRIPTION

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

RETURN VALUE

33       Upon successful completion, writev() shall return the number  of  bytes
34       actually  written.  Otherwise, it shall return a value of -1, the file-
35       pointer shall remain unchanged, and errno shall be set to  indicate  an
36       error.
37

ERRORS

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

EXAMPLES

56   Writing Data from an Array
57       The following example writes data from the buffers specified by members
58       of the iov array to the file associated with the file descriptor fd.
59
60
61              #include <sys/types.h>
62              #include <sys/uio.h>
63              #include <unistd.h>
64              ...
65              ssize_t bytes_written;
66              int fd;
67              char *buf0 = "short string\n";
68              char *buf1 = "This is a longer string\n";
69              char *buf2 = "This is the longest string in this example\n";
70              int iovcnt;
71              struct iovec iov[3];
72
73
74              iov[0].iov_base = buf0;
75              iov[0].iov_len = strlen(buf0);
76              iov[1].iov_base = buf1;
77              iov[1].iov_len = strlen(buf1);
78              iov[2].iov_base = buf2;
79              iov[2].iov_len = strlen(buf2);
80              ...
81              iovcnt = sizeof(iov) / sizeof(struct iovec);
82
83
84              bytes_written = writev(fd, iov, iovcnt);
85              ...
86

APPLICATION USAGE

88       None.
89

RATIONALE

91       Refer to write() .
92

FUTURE DIRECTIONS

94       None.
95

SEE ALSO

97       readv()   ,   write()   ,    the    Base    Definitions    volume    of
98       IEEE Std 1003.1-2001, <limits.h>, <sys/uio.h>
99
101       Portions  of  this text are reprinted and reproduced in electronic form
102       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
103       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
104       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
105       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
106       event of any discrepancy between this version and the original IEEE and
107       The  Open Group Standard, the original IEEE and The Open Group Standard
108       is the referee document. The original Standard can be  obtained  online
109       at http://www.opengroup.org/unix/online.html .
110
111
112
113IEEE/The Open Group                  2003                            WRITEV(P)
Impressum