WRITEV(3)                  POSIX Programmer's Manual                 WRITEV(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       writev -- write a vector

SSYYNNOOPPSSIISS
       #include <sys/uio.h>

       ssize_t writev(int _f_i_l_d_e_s, const struct iovec *_i_o_v, int _i_o_v_c_n_t);

DDEESSCCRRIIPPTTIIOONN
       The _w_r_i_t_e_v() function shall be equivalent to _w_r_i_t_e(), except as
       described below. The _w_r_i_t_e_v() function shall gather output data from
       the _i_o_v_c_n_t buffers specified by the members of the _i_o_v array: _i_o_v[0],
       _i_o_v[1], ..., _i_o_v[_i_o_v_c_n_t-1].  The _i_o_v_c_n_t argument is valid if greater
       than 0 and less than or equal to {IOV_MAX}, as defined in _<_l_i_m_i_t_s_._h_>.

       Each _i_o_v_e_c entry specifies the base address and length of an area in
       memory from which data should be written. The _w_r_i_t_e_v() function shall
       always write a complete area before proceeding to the next.

       If _f_i_l_d_e_s refers to a regular file and all of the _i_o_v___l_e_n members in
       the array pointed to by _i_o_v are 0, _w_r_i_t_e_v() shall return 0 and have no
       other effect. For other file types, the behavior is unspecified.

       If the sum of the _i_o_v___l_e_n values is greater than {SSIZE_MAX}, the
       operation shall fail and no data shall be transferred.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _w_r_i_t_e_v() shall return the number of bytes
       actually written. Otherwise, it shall return a value of -1, the file-
       pointer shall remain unchanged, and _e_r_r_n_o shall be set to indicate an
       error.

EERRRROORRSS
       Refer to _w_r_i_t_e().

       In addition, the _w_r_i_t_e_v() function shall fail if:

       EEIINNVVAALL The sum of the _i_o_v___l_e_n values in the _i_o_v array would overflow an
              ssssiizzee__tt.

       The _w_r_i_t_e_v() function may fail and set _e_r_r_n_o to:

       EEIINNVVAALL The _i_o_v_c_n_t argument was less than or equal to 0, or greater than
              {IOV_MAX}.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
   WWrriittiinngg DDaattaa ffrroomm aann AArrrraayy
       The following example writes data from the buffers specified by members
       of the _i_o_v array to the file associated with the file descriptor _f_d.

           ##iinncclluuddee <<ssyyss//ttyyppeess..hh>>
           ##iinncclluuddee <<ssyyss//uuiioo..hh>>
           ##iinncclluuddee <<uunniissttdd..hh>>
           ......
           ssssiizzee__tt bbyytteess__wwrriitttteenn;;
           iinntt ffdd;;
           cchhaarr **bbuuff00 == ""sshhoorrtt ssttrriinngg\\nn"";;
           cchhaarr **bbuuff11 == ""TThhiiss iiss aa lloonnggeerr ssttrriinngg\\nn"";;
           cchhaarr **bbuuff22 == ""TThhiiss iiss tthhee lloonnggeesstt ssttrriinngg iinn tthhiiss eexxaammppllee\\nn"";;
           iinntt iioovvccnntt;;
           ssttrruucctt iioovveecc iioovv[[33]];;

           iov[0].iov_base = buf0;
           iov[0].iov_len = strlen(buf0);
           iov[1].iov_base = buf1;
           iov[1].iov_len = strlen(buf1);
           iov[2].iov_base = buf2;
           iov[2].iov_len = strlen(buf2);
           ...
           iovcnt = sizeof(iov) / sizeof(struct iovec);

           bytes_written = writev(fd, iov, iovcnt);
           ...

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       Refer to _w_r_i_t_e().

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _r_e_a_d_v(), _w_r_i_t_e()

       The Base Definitions volume of POSIX.1-2008, <<lliimmiittss..hh>>, <<ssyyss__uuiioo..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                            WRITEV(3)
