📄 writev.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>writev</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="writev"></a> <a name="tag_03_867"></a><!-- writev --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_867_01"></a>NAME</h4><blockquote>writev - write a vector</blockquote><h4><a name="tag_03_867_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/sys/uio.h.html">sys/uio.h</a>><br><br> ssize_t writev(int</tt> <i>fildes</i><tt>, const struct iovec *</tt><i>iov</i><tt>, int</tt> <i>iovcnt</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_867_03"></a>DESCRIPTION</h4><blockquote><p>The <i>writev</i>() function shall be equivalent to <a href="../functions/write.html"><i>write</i>()</a>, except as describedbelow. The <i>writev</i>() function shall gather output data from the <i>iovcnt</i> buffers specified by the members of the<i>iov</i> array: <i>iov</i>[0], <i>iov</i>[1], ..., <i>iov</i>[<i>iovcnt</i>-1]. The <i>iovcnt</i> argument is valid if greaterthan 0 and less than or equal to {IOV_MAX}, as defined in <a href="../basedefs/limits.h.html"><i><limits.h></i></a>.</p><p>Each <i>iovec</i> entry specifies the base address and length of an area in memory from which data should be written. The<i>writev</i>() function shall always write a complete area before proceeding to the next.</p><p>If <i>fildes</i> refers to a regular file and all of the <i>iov_len</i> members in the array pointed to by <i>iov</i> are 0,<i>writev</i>() shall return 0 and have no other effect. For other file types, the behavior is unspecified.</p><p>If the sum of the <i>iov_len</i> values is greater than {SSIZE_MAX}, the operation shall fail and no data shall betransferred.</p></blockquote><h4><a name="tag_03_867_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>writev</i>() shall return the number of bytes actually written. Otherwise, it shall return avalue of -1, the file-pointer shall remain unchanged, and <i>errno</i> shall be set to indicate an error.</p></blockquote><h4><a name="tag_03_867_05"></a>ERRORS</h4><blockquote><p>Refer to <a href="write.html"><i>write</i>()</a> .</p><p>In addition, the <i>writev</i>() function shall fail if:</p><dl compact><dt>[EINVAL]</dt><dd>The sum of the <i>iov_len</i> values in the <i>iov</i> array would overflow an <b>ssize_t</b>.</dd></dl><p>The <i>writev</i>() function may fail and set <i>errno</i> to:</p><dl compact><dt>[EINVAL]</dt><dd>The <i>iovcnt</i> argument was less than or equal to 0, or greater than {IOV_MAX}.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_867_06"></a>EXAMPLES</h4><blockquote><h5><a name="tag_03_867_06_01"></a>Writing Data from an Array</h5><p>The following example writes data from the buffers specified by members of the <i>iov</i> array to the file associated with thefile descriptor <i>fd</i>.</p><pre><tt>#include <sys/types.h>#include <sys/uio.h>#include <unistd.h>...ssize_t bytes_written;int fd;char *buf0 = "short string\n";char *buf1 = "This is a longer string\n";char *buf2 = "This is the longest string in this example\n";int iovcnt;struct iovec iov[3];<br>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);<br>bytes_written = writev(fd, iov, iovcnt);...</tt></pre></blockquote><h4><a name="tag_03_867_07"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_867_08"></a>RATIONALE</h4><blockquote><p>Refer to <a href="write.html"><i>write</i>()</a> .</p></blockquote><h4><a name="tag_03_867_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_867_10"></a>SEE ALSO</h4><blockquote><p><a href="readv.html"><i>readv</i>()</a> , <a href="write.html"><i>write</i>()</a> , the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/limits.h.html"><i><limits.h></i></a>, <a href="../basedefs/sys/uio.h.html"><i><sys/uio.h></i></a></p></blockquote><h4><a name="tag_03_867_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 4, Version 2.</p></blockquote><h4><a name="tag_03_867_12"></a>Issue 6</h4><blockquote><p>Split out from the <a href="../functions/write.html"><i>write</i>()</a> reference page.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -