OSDN Git Service

(split) Correct a typo in readv.2. [JM:00545]
[linuxjm/LDP_man-pages.git] / draft / man2 / readv.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (C) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" and Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" License.
26 .\" Modified Sat Jul 24 18:34:44 1993 by Rik Faith (faith@cs.unc.edu)
27 .\" Merged readv.[23], 2002-10-17, aeb
28 .\" 2007-04-30 mtk, A fairly major rewrite to fix errors and
29 .\"     add more details.
30 .\"
31 .\" 1996-04-12 Tom Bjorkholm <tomb@mydata.se>
32 .\"            First version written
33 .\" Modified Tue Oct 22 17:41:07 1996 by Eric S. Raymond <esr@thyrsus.com>
34 .\"
35 .\" Japanese Version Copyright (c) 1997-1999 HANATAKA Shinya
36 .\"         all rights reserved.
37 .\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
38 .\" Updated 1999-04-03, HANATAKA Shinya
39 .\" Updated 2003-01-14, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
40 .\" Updated 2005-10-07, Akihiro MOTOKI
41 .\" Updated 2007-06-01, Akihiro MOTOKI, LDP v2.50
42 .\"
43 .\"WORD:        vector                  ¥Ù¥¯¥¿ (vector)
44 .\"WORD:        file descriptor         ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
45 .\"WORD:        buffer                  ¥Ð¥Ã¥Õ¥¡
46 .\"
47 .TH READV 2  2002-10-17 "Linux" "Linux Programmer's Manual"
48 .\"O .SH NAME
49 .\"O readv, writev \- read or write data into multiple buffers
50 .SH Ì¾Á°
51 readv, writev \- Ê£¿ô¤Î¥Ð¥Ã¥Õ¥¡¤Ø¤ÎÆɤ߽ñ¤­¤ò¹Ô¤Ê¤¦
52 .\"O .SH SYNOPSIS
53 .SH ½ñ¼°
54 .nf
55 .B #include <sys/uio.h>
56 .sp
57 .BI "ssize_t readv(int " fd ", const struct iovec *" iov ", int " iovcnt );
58 .sp
59 .BI "ssize_t writev(int " fd ", const struct iovec *" iov ", int " iovcnt );
60 .fi
61 .\"O .SH DESCRIPTION
62 .SH ÀâÌÀ
63 .\"O The
64 .\"O .BR readv ()
65 .\"O function reads
66 .\"O .I iovcnt
67 .\"O buffers from the file associated with the file descriptor
68 .\"O .I fd
69 .\"O into the buffers described by
70 .\"O .I iov
71 .\"O ("scatter input").
72 .BR readv ()
73 ´Ø¿ô¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
74 .I fd
75 ¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Õ¥¡¥¤¥ë¤«¤é¡¢
76 .I iovcnt
77 ¸Ä¤Î¥Ð¥Ã¥Õ¥¡Ê¬¤Î¥Ç¡¼¥¿¤òÆɤ߹þ¤ß¡¢
78 .I iov
79 ¤Ç»ØÄꤵ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤Ë³ÊǼ¤¹¤ë
80 ("scatter input";¡Ö¤Ð¤é¤Þ¤­ÆþÎÏ¡×)¡£
81 .PP
82 .\"O The
83 .\"O .BR writev ()
84 .\"O function writes at most
85 .\"O .I iovcnt
86 .\"O buffers described by
87 .\"O .I iov
88 .\"O to the file associated with the file descriptor
89 .\"O .I fd
90 .\"O ("gather output").
91 .BR writev ()
92 ´Ø¿ô¤Ï¡¢
93 .I iov
94 ¤Ç»ØÄꤵ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤«¤éºÇÂç
95 .I iovcnt
96 ¸Ä¤Î¥Ð¥Ã¥Õ¥¡Ê¬¤Î¥Ç¡¼¥¿¤ò¼è¤ê½Ð¤·¡¢
97 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
98 .I fd
99 ¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Õ¥¡¥¤¥ë¤Ë½ñ¤­¹þ¤à
100 ("gather output";¡Ö¤«¤­½¸¤á½ÐÎÏ¡×)¡£
101 .PP
102 .\"O The pointer
103 .\"O .I iov
104 .\"O points to an array of
105 .\"O .I iovec
106 .\"O structures,
107 .\"O defined in
108 .\"O .I <sys/uio.h>
109 .\"O as:
110 ¥Ý¥¤¥ó¥¿
111 .I iov
112 ¤Ï
113 .I iovec
114 ¹½Â¤ÂΤÎÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
115 .I iovec
116 ¹½Â¤ÂΤÏ
117 .I <sys/uio.h>
118 ¤Ç°Ê²¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
119 .PP
120 .br
121 .in +4n
122 .nf
123 struct iovec {
124     void  *iov_base;    /* Starting address */
125     size_t iov_len;     /* Number of bytes to transfer */
126 };
127 .fi
128 .in
129 .PP
130 .\"O The
131 .\"O .BR readv ()
132 .\"O function works just like
133 .\"O .BR read (2)
134 .\"O except that multiple buffers are filled.
135 .BR readv ()
136 ´Ø¿ô¤Ï¡¢Ê£¿ô¤Î¥Ð¥Ã¥Õ¥¡¤Ë¥Ç¡¼¥¿¤òÆɤ߹þ¤àÅÀ¤ò½ü¤¤¤Æ
137 .BR read (2)
138 ¤ÈÁ´¤¯Æ±ÍͤÎÆ°ºî¤ò¹Ô¤¦¡£
139 .PP
140 .\"O The
141 .\"O .BR writev ()
142 .\"O function works just like
143 .\"O .BR write (2)
144 .\"O except that multiple buffers are written out.
145 .BR writev ()
146 ´Ø¿ô¤Ï¡¢Ê£¿ô¤Î¥Ð¥Ã¥Õ¥¡¤Î¥Ç¡¼¥¿¤ò½ñ¤­½Ð¤¹ÅÀ°Ê³°¤Ï
147 .BR write (2)
148 ¤ÈÁ´¤¯Æ±ÍͤÎÆ°ºî¤ò¹Ô¤¦¡£
149 .PP
150 .\"O Buffers are processed in array order.
151 .\"O This means that
152 .\"O .BR readv ()
153 .\"O completely fills
154 .\"O .IR iov [0]
155 .\"O before proceeding to
156 .\"O .IR iov [1],
157 .\"O and so on.
158 .\"O (If there is insufficient data, then not all buffers pointed to by
159 .\"O .I iov
160 .\"O may be filled.)
161 .\"O Similarly,
162 .\"O .BR writev ()
163 .\"O writes out the entire contents of
164 .\"O .IR iov [0]
165 .\"O before proceeding to
166 .\"O .IR iov [1],
167 .\"O and so on.
168 ¥Ð¥Ã¥Õ¥¡¤ÏÇÛÎó¤Î½ç½ø¤Ç½èÍý¤µ¤ì¤ë¡£¤³¤ì¤Ï¡¢
169 .BR readv ()
170 ¤¬
171 .IR iov [0]
172 ¤¬´°Á´¤Ë°ìÇդˤʤë¤Þ¤Ç¥Ç¡¼¥¿¤òµÍ¤á¤Æ¤«¤é¡¢
173 .IR iov [1]
174 ¤Ê¤É¤Ë¿Ê¤à¤³¤È¤ò°ÕÌ£¤¹¤ë
175 (¥Ç¡¼¥¿¤¬½½Ê¬¤Ê¤¤¾ì¹ç¤Ï¡¢
176 .I iov
177 ¤¬»Ø¤¹¥Ð¥Ã¥Õ¥¡¤Î¤¤¤º¤ì¤â°ìÇդˤʤé¤Ê¤¤)¡£
178 ƱÍͤˡ¢
179 .BR writev ()
180 ¤Ï
181 .IR iov [0]
182 ¤ÎÆâÍƤòÁ´Éô½ñ¤­½Ð¤·¤Æ¤«¤é
183 .IR iov [1]
184 ¤Ê¤É¤Ë¿Ê¤à¡£
185 .PP
186 .\"O The data transfers performed by
187 .\"O .BR readv ()
188 .\"O and
189 .\"O .BR writev ()
190 .\"O are atomic: the data written by
191 .\"O .BR writev ()
192 .\"O is written as a single block that is not intermingled with output
193 .\"O from writes in other processes (but see
194 .\"O .BR pipe (7)
195 .\"O for an exception);
196 .\"O analogously,
197 .\"O .BR readv ()
198 .\"O is guaranteed to read a contiguous block of data from the file,
199 .\"O regardless of read operations performed in other threads or processes
200 .\"O that have file descriptors referring to the same open file description
201 .\"O (see
202 .\"O .BR open (2)).
203 .BR readv ()
204 ¤È
205 .BR writev ()
206 ¤Ë¤è¤ë¥Ç¡¼¥¿Å¾Á÷¤Ï atomic ¤Ë¹Ô¤ï¤ì¤ë¡£¤Ä¤Þ¤ê¡¢
207 .BR writev ()
208 ¤Ë¤è¤ë¥Ç¡¼¥¿½ñ¤­¹þ¤ß¤Ï°ì¤Ä¤Î¥Ö¥í¥Ã¥¯¤È¤·¤Æ¹Ô¤ï¤ì¡¢Â¾¤Î¥×¥í¥»¥¹¤Î
209 write ¤Ë¤è¤ë½ñ¤­¹þ¤ß¤Èº®¤¶¤ê¹ç¤¦¤³¤È¤Ï¤Ê¤¤
210 (Îã³°¤Ë´Ø¤·¤Æ¤Ï
211 .BR pipe (7)
212 ¤ò»²¾È¤Î¤³¤È)¡£Æ±Íͤˡ¢
213 .BR readv ()
214 ¤Ï¥Õ¥¡¥¤¥ë¤«¤éϢ³¤¹¤ë¥Ç¡¼¥¿¥Ö¥í¥Ã¥¯¤¬Æɤ߽Ф¹¤³¤È¤¬Êݾڤµ¤ì¡¢
215 Ʊ¤¸¥Õ¥¡¥¤¥ëµ­½Ò (file description;
216 .BR open (2)
217 »²¾È) ¤ò»²¾È¤¹¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò»ý¤Ä¾¤Î¥¹¥ì¥Ã¥É¤ä¥×¥í¥»¥¹¤¬
218 ¼Â¹Ô¤·¤¿ read Áàºî¤Î±Æ¶Á¤ò¼õ¤±¤ë¤³¤È¤Ï¤Ê¤¤¡£
219 .\"O .SH "RETURN VALUE"
220 .SH ÊÖ¤êÃÍ
221 .\"O On success, the
222 .\"O .BR readv ()
223 .\"O function returns the number of bytes read; the
224 .\"O .BR writev ()
225 .\"O function returns the number of bytes written.
226 .\"O On error, \-1 is returned, and \fIerrno\fP is set appropriately.
227 À®¸ù¤·¤¿¾ì¹ç¡¢
228 .BR readv ()
229 ´Ø¿ô¤ÏÆɤ߹þ¤ó¤À¥Ð¥¤¥È¿ô¤òÊÖ¤·¡¢
230 .BR writev ()
231 ´Ø¿ô¤Ï½ñ¤­¹þ¤ó¤À¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£
232 ¥¨¥é¡¼¤Î¾ì¹ç \-1 ¤òÊÖ¤·¡¢\fIerrno\fP ¤òŬÀÚ¤ËÀßÄꤹ¤ë¡£
233 .\"O .SH ERRORS
234 .SH ¥¨¥é¡¼
235 .\"O The errors are as given for
236 .\"O .BR read (2)
237 .\"O and
238 .\"O .BR write (2).
239 .BR read (2)
240 ¤ä
241 .BR write (2)
242 ¤ÈƱ¤¸¥¨¥é¡¼¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
243 .\"O Additionally the following error is defined:
244 ¤µ¤é¤Ë°Ê²¼¤Î¥¨¥é¡¼¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
245 .TP
246 .B EINVAL
247 .\"O The sum of the
248 .\"O .I iov_len
249 .\"O values overflows an
250 .\"O .I ssize_t
251 .\"O value.
252 .\"O Or, the vector count \fIiovcnt\fP is less than zero or greater than the
253 .\"O permitted maximum.
254 .I iov_len
255 ¤Î¹ç·×¤¬
256 .I ssize_t
257 ¤ÎÈϰϤò¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤·¤¿¡£¤â¤·¤¯¤Ï¡¢
258 ¥Ù¥¯¥¿¿ô \fIiovcnt\fP ¤¬ 0 ¤è¤ê¾®¤µ¤¤¤«µö²Ä¤µ¤ì¤¿ºÇÂçÃͤè¤ê¤âÂ礭¤«¤Ã¤¿¡£
259 .\"O .SH "CONFORMING TO"
260 .SH ½àµò
261 .\"O 4.4BSD (the
262 .\"O .BR readv ()
263 .\"O and
264 .\"O .BR writev ()
265 .\"O functions first appeared in 4.2BSD), POSIX.1-2001.
266 .\"O Linux libc5 used \fIsize_t\fP as the type of the \fIiovcnt\fP argument,
267 .\"O and \fIint\fP as return type for these functions.
268 .\"O .\" The readv/writev system calls were buggy before Linux 1.3.40.
269 .\"O .\" (Says release.libc.)
270 4.4BSD
271 .RB ( readv ()
272 ¤È
273 .BR writev ()
274 ´Ø¿ô¤Ï 4.2BSD ¤ÇºÇ½é¤Ë¸½¤ï¤ì¤¿)¡¢POSIX.1-2001¡£
275 Linux libc5 ¤Ç¤Ï \fIiovcnt\fP °ú¤­¿ô¤Î·¿¤È¤·¤Æ \fIsize_t\fP ¤ò¡¢
276 ¤³¤ì¤é¤Î´Ø¿ô¤ÎÊÖ¤êÃͤȤ·¤Æ \fIint\fP ¤ò»ÈÍѤ·¤Æ¤¤¤¿¡£
277 .\" readv/writev ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï Linux 1.3.40 °ÊÁ°¤Ï¥Ð¥°¤À¤é¤±¤Ç¤¢¤Ã¤¿
278 .\" (¤È release.libc ¤Ë½ñ¤«¤ì¤Æ¤¤¤ë)¡£
279 .\"O .SH NOTES
280 .\"O .SS Linux Notes
281 .SH Ãí°Õ
282 .SS "Linux ¤Ç¤ÎÃí°Õ"
283 .\"O POSIX.1-2001 allows an implementation to place a limit on
284 .\"O the number of items that can be passed in
285 .\"O .IR iov .
286 .\"O An implementation can advertise its limit by defining
287 .\"O .B IOV_MAX
288 .\"O in
289 .\"O .IR <limits.h>
290 .\"O or at run time via the return value from
291 .\"O .IR sysconf(_SC_IOV_MAX) .
292 .\"O On Linux, the limit advertised by these mechanisms is 1024,
293 .\"O which is the true kernel limit.
294 POSIX.1-2001 ¤Ç¤Ï¡¢
295 .I iov
296 ¤ÇÅϤ¹¤³¤È¤¬¤Ç¤­¤ëÍ×ÁÇ¿ô¤Ë¾å¸Â¤òÀߤ±¤ë¼ÂÁõ¤¬Ç§¤á¤é¤ì¤Æ¤¤¤ë¡£
297 ¼ÂÁõ¤Ï¡¢
298 .I <limits.h>
299 ¤Î
300 .B IOV_MAX
301 ¤òÄêµÁ¤¹¤ë¤³¤È¤ä¡¢¼Â¹Ô»þ¤Ë
302 .I sysconf(_SC_IOV_MAX)
303 ¤ÎÊÖ¤êÃÍ·Ðͳ¤Ç¡¢¤³¤Î¾å¸Â¤ò¹­¹ð¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
304 Linux ¤Ç¤Ï¡¢¤³¤Î»ÅÁȤߤˤè¤ê¹­¹ð¤µ¤ì¤ë¾å¸Â¤Ï 1024 ¤Ç¤¢¤ê¡¢
305 ¤³¤ÎÃͤϥ«¡¼¥Í¥ë¤Ç¤Î¾å¸Â¤½¤Î¤â¤Î¤Ç¤¢¤ë¡£
306 .\"O However, the glibc wrapper functions do some extra work if
307 .\"O they detect that the underlying kernel system call failed because this
308 .\"O limit was exceeded.
309 .\"O In the case of
310 .\"O .BR readv ()
311 .\"O the wrapper function allocates a temporary buffer large enough
312 .\"O for all of the items specified by
313 .\"O .IR iov ,
314 .\"O passes that buffer in a call to
315 .\"O .BR read (2),
316 .\"O copies data from the buffer to the locations specified by the
317 .\"O .I iov_base
318 .\"O fields of the elements of
319 .\"O .IR iov ,
320 .\"O and then frees the buffer.
321 .\"O The wrapper function for
322 .\"O .BR writev ()
323 .\"O performs the analogous task using a temporary buffer and a call to
324 .\"O .BR write (2).
325 °ìÊý¤Ç¡¢glibc ¤Î¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ï¡¢¤½¤Î´Ø¿ô¤ÎÆâÉô¤Ç¸Æ¤Ð¤ì¤ë¥«¡¼¥Í¥ë¡¦
326 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤¬¤³¤Î¾å¸Â¤òĶ²á¤·¤Æ¼ºÇÔ¤·¤¿¤³¤È¤ò¸¡½Ð¤¹¤ë¤È¡¢
327 ÄɲäÎÆ°ºî¤ò¤¹¤ë¡£
328 .BR readv ()
329 ¤Î¾ì¹ç¡¢¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ï
330 .I iov
331 ¤Ç»ØÄꤵ¤ì¤¿Á´¤Æ¤ÎÍ×ÁǤò³ÊǼ¤Ç¤­¤ëÂ礭¤µ¤Î°ì»þ¥Ð¥Ã¥Õ¥¡¤ò³ä¤êÅö¤Æ¡¢
332 .BR read (2)
333 ¤ò¸Æ¤Ó½Ð¤¹ºÝ¤Ë¤½¤Î¥Ð¥Ã¥Õ¥¡¤òÅϤ·¡¢
334 ¤½¤Î¥Ð¥Ã¥Õ¥¡¤Î¥Ç¡¼¥¿¤ò
335 .I iov
336 ¤Î³ÆÍ×ÁǤÎ
337 .I iov_base
338 ¥Õ¥£¡¼¥ë¥É¤¬»ØÄꤹ¤ë¾ì½ê¤Ë¥³¥Ô¡¼¤·¤Æ¤«¤é¡¢
339 ¤½¤Î¥Ð¥Ã¥Õ¥¡¤ò²òÊü¤¹¤ë¡£
340 .BR writev ()
341 ¤Î¥é¥Ã¥Ñ¡¼´Ø¿ô¤â¡¢Æ±¤¸¤è¤¦¤Ë°ì»þ¥Ð¥Ã¥Õ¥¡¤ò»È¤Ã¤Æ
342 .BR write (2)
343 ¤ò¸Æ¤Ó½Ð¤¹¡£
344 .\"O .SH BUGS
345 .SH ¥Ð¥°
346 .\"O It is not advisable to mix calls to functions like
347 .\"O .BR readv ()
348 .\"O or
349 .\"O .BR writev (),
350 .\"O which operate on file descriptors, with the functions from the stdio
351 .\"O library; the results will be undefined and probably not what you want.
352 .BR readv ()
353 ¤ä
354 .BR writev ()
355 ¤Î¤è¤¦¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂФ¹¤ëÁàºî¤ò¹Ô¤¦´Ø¿ô¤È¡¢
356 ɸ½àÆþ½ÐÎϥ饤¥Ö¥é¥ê¤Î´Ø¿ô¤ò¤´¤Á¤ã¤Þ¤¼¤Ë¤·¤Æ¸Æ¤Ö¤Î¤Ï¤ªÁ¦¤á¤·¤Ê¤¤¡£
357 ¤É¤ó¤Ê·ë²Ì¤Ë¤Ê¤ë¤«¤ÏÄêµÁ¤µ¤ì¤Æ¤ª¤é¤º¡¢
358 ¤ª¤½¤é¤¯Íߤ·¤¤·ë²Ì¤ÏÆÀ¤é¤ì¤Ê¤¤¤À¤í¤¦¡£
359 .\"O .SH EXAMPLE
360 .SH Îã
361 .\"O The following code sample demonstrates the use of
362 .\"O .BR writev ():
363 °Ê²¼¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï
364 .BR writev ()
365 ¤Î»ÈÍÑÊýË¡¤ò¼¨¤¹¤â¤Î¤Ç¤¢¤ë¡£
366
367 .in +4n
368 .nf
369 char *str0 = "hello ";
370 char *str1 = "world\\n";
371 struct iovec iov[2];
372 ssize_t nwritten;
373
374 iov[0].iov_base = str0;
375 iov[0].iov_len = strlen(str0);
376 iov[1].iov_base = str1;
377 iov[1].iov_len = strlen(str1);
378
379 nwritten = writev(STDOUT_FILENO, iov, 2);
380 .fi
381 .in
382 .\"O .SH "SEE ALSO"
383 .SH ´ØÏ¢¹àÌÜ
384 .BR read (2),
385 .BR write (2)