OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man2 / read.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\"                               1993 Michael Haardt, Ian Jackson.
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 .\"
26 .\" Modified Sat Jul 24 00:06:00 1993 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified Wed Jan 17 16:02:32 1996 by Michael Haardt
28 .\"   <michael@cantor.informatik.rwth-aachen.de>
29 .\" Modified Thu Apr 11 19:26:35 1996 by Andries Brouwer <aeb@cwi.nl>
30 .\" Modified Sun Jul 21 18:59:33 1996 by Andries Brouwer <aeb@cwi.nl>
31 .\" Modified Fri Jan 31 16:47:33 1997 by Eric S. Raymond <esr@thyrsus.com>
32 .\" Modified Sat Jul 12 20:45:39 1997 by Michael Haardt
33 .\"   <michael@cantor.informatik.rwth-aachen.de>
34 .\"
35 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
36 .\"         all rights reserved.
37 .\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
38 .\" Modified 1997-09-28, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
39 .\" Updated & Modified 2005-02-24, Yuichi SATO <ysato444@yahoo.co.jp>
40 .\" Updated 2005-09-06, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
41 .\" Updated 2005-10-14, Akihiro MOTOKI
42 .\" Updated 2008-02-10, Akihiro MOTOKI, LDP v2.77
43 .\" Updated 2009-04-13, Akihiro MOTOKI, LDP v3.20
44 .\"
45 .\"WORD:        descriptor              ¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼
46 .\"WORD:        buffer                  ¥Ð¥Ã¥Õ¥¡¡¼
47 .\"WORD:        signal                  ¥·¥°¥Ê¥ë
48 .\"WORD:        process group           ¥×¥í¥»¥¹¡¦¥°¥ë¡¼¥×
49 .\"WORD:        backgraound             ¥Ð¥Ã¥¯¥°¥é¥ó¥É
50 .\"WORD:        orphan                  ¸ÉΩ
51 .\"WORD:        open                    ¥ª¡¼¥×¥ó
52 .\"WORD:        directory               ¥Ç¥£¥ì¥¯¥È¥ê
53 .\"WORD:        object                  ¥ª¥Ö¥¸¥§¥¯¥È
54 .\"
55 .TH READ 2 2009-02-23 "Linux" "Linux Programmer's Manual"
56 .\"O .SH NAME
57 .SH Ì¾Á°
58 .\"O read \- read from a file descriptor
59 read \- ¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼¤«¤éÆɤ߹þ¤à
60 .\"O .SH SYNOPSIS
61 .SH ½ñ¼°
62 .nf
63 .B #include <unistd.h>
64 .sp
65 .BI "ssize_t read(int " fd ", void *" buf ", size_t " count );
66 .fi
67 .\"O .SH DESCRIPTION
68 .SH ÀâÌÀ
69 .\"O .BR read ()
70 .\"O attempts to read up to
71 .\"O .I count
72 .\"O bytes from file descriptor
73 .\"O .I fd
74 .\"O into the buffer starting at
75 .\"O .IR buf .
76 .BR read ()
77 ¤Ï¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼ (file descriptor)
78 .I fd
79 ¤«¤éºÇÂç
80 .I count
81 ¥Ð¥¤¥È¤ò
82 .I buf
83 ¤Ç»Ï¤Þ¤ë¥Ð¥Ã¥Õ¥¡¡¼¤ØÆɤ߹þ¤â¤¦¤È¤¹¤ë¡£
84 .PP
85 .\"O If
86 .\"O .I count
87 .\"O is zero,
88 .\"O .BR read ()
89 .\"O returns zero and has no other results.
90 .\"O If
91 .\"O .I count
92 .\"O is greater than
93 .\"O .BR SSIZE_MAX ,
94 .\"O the result is unspecified.
95 .I count
96 ¤¬ 0 ¤Ê¤é¤Ð¡¢
97 .BR read ()
98 ¤Ï 0 ¤òÊÖ¤·¡¢Â¾¤Ë²¿¤âµ¯¤­¤Ê¤¤¡£
99 .I count
100 ¤¬
101 .B SSIZE_MAX
102 ¤è¤êÂ礭¤±¤ì¤Ð¡¢·ë²Ì¤ÏÆÃÄê¤Ç¤­¤Ê¤¤¡£
103 .\"O .SH "RETURN VALUE"
104 .SH ÊÖ¤êÃÍ
105 .\"O On success, the number of bytes read is returned (zero indicates end of
106 .\"O file), and the file position is advanced by this number.
107 .\"O It is not an error if this number is smaller than the number of bytes
108 .\"O requested; this may happen for example because fewer bytes are actually
109 .\"O available right now (maybe because we were close to end-of-file, or
110 .\"O because we are reading from a pipe, or from a terminal), or because
111 .\"O .BR read ()
112 .\"O was interrupted by a signal.
113 À®¸ù¤·¤¿¾ì¹ç¡¢Æɤ߹þ¤ó¤À¥Ð¥¤¥È¿ô¤òÊÖ¤¹ (0 ¤Ï¥Õ¥¡¥¤¥ë¤Î½ª¤ê¤ò°ÕÌ£¤¹¤ë)¡£
114 ¥Õ¥¡¥¤¥ë°ÌÃ֤Ϥ³¤Î¿ô¤À¤±¿Ê¤á¤é¤ì¤ë¡£
115 ¤³¤Î¿ô¤¬Í׵ᤷ¤¿¿ô¤è¤ê¾®¤µ¤«¤Ã¤¿¤È¤·¤Æ¤â¥¨¥é¡¼¤Ç¤Ï¤Ê¤¤;
116 Î㤨¤Ðº£¤¹¤°¤Ë¤Ï¼ÂºÝ¤Ë¤½¤ì¤À¤±¤Î¿ô¤·¤«¤Ê¤¤¾ì¹ç (¥Õ¥¡¥¤¥ë¤ÎºÇ¸å¤Ë¶á¤¤¤Î¤«¤â
117 ¤·¤ì¤Ê¤¤¤·¡¢¥Ñ¥¤¥× (pipe) ¤äüËö (terminal) ¤«¤éÆɤ߹þ¤ó¤Ç¤¤¤ë¤«¤â¤·¤ì¤Ê¤¤) ¤ä
118 .BR read ()
119 ¤¬¥·¥°¥Ê¥ë (signal) ¤Ë¤è¤Ã¤Æ³ä¤ê¹þ¤Þ¤ì¤¿¾ì¹ç¤Ë¤³¤ì¤Ïµ¯¤³¤ê¤¨¤ë¡£
120 .\"O On error, \-1 is returned, and
121 .\"O .I errno
122 .\"O is set appropriately.
123 .\"O In this case it is left unspecified whether
124 .\"O the file position (if any) changes.
125 ¥¨¥é¡¼¤Î¾ì¹ç¤Ï¡¢\-1 ¤¬ÊÖ¤µ¤ì¡¢
126 .I errno
127 ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£¤³¤Î¾ì¹ç¤Ï¥Õ¥¡¥¤¥ë°ÌÃÖ¤¬Êѹ¹¤µ¤ì¤ë¤«¤É¤¦¤«¤Ï
128 ÉÔÄê¤Ç¤¢¤ë¡£
129 .SH ¥¨¥é¡¼
130 .TP
131 .B EAGAIN
132 .\"O The file descriptor
133 .\"O .I fd
134 .\"O refers to a file other than a socket and has been marked nonblocking
135 .\"O .RB ( O_NONBLOCK ),
136 .\"O and the read would block.
137 ¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼
138 .I fd
139 ¤¬¥½¥±¥Ã¥È°Ê³°¤Î¥Õ¥¡¥¤¥ë¤ò»²¾È¤·¤Æ¤¤¤Æ¡¢
140 ÈóÄä»ß (nonblocking) ¥â¡¼¥É
141 .RB ( O_NONBLOCK )
142 ¤ËÀßÄꤵ¤ì¤Æ¤ª¤ê¡¢Æɤ߹þ¤ß¤ò¹Ô¤¦¤ÈÄä»ß¤¹¤ë¾õ¶·¤Ë¤¢¤ë¡£
143 .TP
144 .\"O .BR EAGAIN " or " EWOULDBLOCK
145 .BR EAGAIN " ¤Þ¤¿¤Ï " EWOULDBLOCK
146 .\" Actually EAGAIN on Linux
147 .\"O The file descriptor
148 .\"O .I fd
149 .\"O refers to a socket and has been marked nonblocking
150 .\"O .RB ( O_NONBLOCK ),
151 .\"O and the read would block.
152 .\"O POSIX.1-2001 allows either error to be returned for this case,
153 .\"O and does not require these constants to have the same value,
154 .\"O so a portable application should check for both possibilities.
155 ¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼
156 .I fd
157 ¤¬¥½¥±¥Ã¥È¤ò»²¾È¤·¤Æ¤¤¤Æ¡¢ÈóÄä»ß (nonblocking) ¥â¡¼¥É
158 .RB ( O_NONBLOCK )
159 ¤ËÀßÄꤵ¤ì¤Æ¤ª¤ê¡¢Æɤ߹þ¤ß¤ò¹Ô¤¦¤ÈÄä»ß¤¹¤ë¾õ¶·¤Ë¤¢¤ë¡£
160 POSIX.1-2001 ¤Ï¡¢¤³¤Î¾ì¹ç¤Ë¤É¤Á¤é¤Î¥¨¥é¡¼¤òÊÖ¤¹¤³¤È¤âǧ¤á¤Æ¤ª¤ê¡¢
161 ¤³¤ì¤é 2 ¤Ä¤ÎÄê¿ô¤¬Æ±¤¸Ãͤò»ý¤Ä¤³¤È¤âµá¤á¤Æ¤¤¤Ê¤¤¡£
162 ¤·¤¿¤¬¤Ã¤Æ¡¢°Ü¿¢À­¤¬É¬Íפʥ¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¡¢Î¾Êý¤Î²ÄǽÀ­¤ò
163 ³Îǧ¤¹¤Ù¤­¤Ç¤¢¤ë¡£
164 .TP
165 .B EBADF
166 .\"O .I fd
167 .\"O is not a valid file descriptor or is not open for reading.
168 .I fd
169 ¤¬Í­¸ú¤Ê¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼¤Ç¤Ê¤¤¤«¡¢Æɤ߹þ¤ß¤Î¤¿¤á¤Ë
170 ¥ª¡¼¥×¥ó (open) ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
171 .TP
172 .B EFAULT
173 .\"O .I buf
174 .\"O is outside your accessible address space.
175 .I buf
176 ¤¬¥¢¥¯¥»¥¹²Äǽ¤Ê¥¢¥É¥ì¥¹¶õ´Ö¤Î³°¤Ë¤¢¤ë¡£
177 .TP
178 .B EINTR
179 .\"O The call was interrupted by a signal before any data was read; see
180 .\"O .BR signal (7).
181 ²¿¤Î¥Ç¡¼¥¿¤âÆɤ߹þ¤Þ¤Ê¤¤¤¦¤Á¤Ë¥·¥°¥Ê¥ë¤Ë³ä¤ê¹þ¤Þ¤ì¤¿¡£
182 .BR signal (7)
183 »²¾È¡£
184 .TP
185 .B EINVAL
186 .\"O .I fd
187 .\"O is attached to an object which is unsuitable for reading;
188 .\"O or the file was opened with the
189 .\"O .B O_DIRECT
190 .\"O flag, and either the address specified in
191 .\"O .IR buf ,
192 .\"O the value specified in
193 .\"O .IR count ,
194 .\"O or the current file offset is not suitably aligned.
195 .I fd
196 ¤ÏÆɤ߹þ¤ß¤ËŬ¤·¤Æ¤¤¤Ê¤¤¥ª¥Ö¥¸¥§¥¯¥È¤ò»²¾È¤·¤Æ¤¤¤ë¡£
197 ¤â¤·¤¯¤Ï¡¢¥Õ¥¡¥¤¥ë¤¬
198 .B O_DIRECT
199 ¥Õ¥é¥°¤ò»ØÄꤷ¤Æ¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¤¬¡¢
200 .I buf
201 ¤Ë»ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹¡¢
202 .I count
203 ¤Ë»ØÄꤵ¤ì¤¿ÃÍ¡¢
204 ¸½ºß¤Î¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤Î¤¤¤º¤ì¤«¤Î
205 ¥¢¥é¥¤¥ó¥á¥ó¥È¤¬ÉÔŬÀڤǤ¢¤ë¡£
206 .TP
207 .B EINVAL
208 .\"O .I fd
209 .\"O was created via a call to
210 .\"O .BR timerfd_create (2)
211 .\"O and the wrong size buffer was given to
212 .\"O .BR read ();
213 .\"O see
214 .\"O .BR timerfd_create (2)
215 .\"O for further information.
216 .I fd
217 ¤¬
218 .BR timerfd_create (2)
219 ¤Î¸Æ¤Ó½Ð¤·¤ÇºîÀ®¤µ¤ì¤¿¤¬¡¢
220 .BR read ()
221 ¤Ë´Ö°ã¤Ã¤¿¥µ¥¤¥º¤Î¥Ð¥Ã¥Õ¥¡¤¬ÅϤµ¤ì¤¿¡£
222 ¤µ¤é¤Ê¤ë¾ðÊó¤Ï
223 .BR timerfd_create (2)
224 ¤ò»²¾È¤Î¤³¤È¡£
225 .TP
226 .B EIO
227 .\"O I/O error.
228 .\"O This will happen for example when the process is in a
229 .\"O background process group, tries to read from its controlling tty,
230 .\"O and either it is ignoring or blocking
231 .\"O .B SIGTTIN
232 .\"O or its process group
233 .\"O is orphaned.
234 .\"O It may also occur when there is a low-level I/O error
235 .\"O while reading from a disk or tape.
236 I/O ¥¨¥é¡¼¡£¤³¤ì¤ÏÎ㤨¤Ð¥×¥í¥»¥¹¤¬¥Ð¥Ã¥¯¥°¥é¥ó¥É¡¦¥×¥í¥»¥¹¡¦¥°¥ë¡¼¥×¤Ç¡¢
237 ¤½¤ì¤òÀ©¸æ¤·¤Æ¤¤¤ë tty ¤«¤éÆɤ߹þ¤â¤¦¤È¤·¡¢
238 .B SIGTTIN
239 ¤¬Ìµ»ë (ignore) ¤Þ¤¿¤Ï¶Ø»ß (blocking) ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤ä¡¢
240 ¤½¤Î¥×¥í¥»¥¹¡¦¥°¥ë¡¼¥×¤¬¸ÉΩ (orphan) ¤·¤Æ¤¤¤ë¾ì¹ç¤Ëµ¯¤³¤ë¡£
241 ¤Þ¤¿¥Ç¥£¥¹¥¯¤ä¥Æ¡¼¥×¤òÆɤó¤Ç¤¤¤ë»þ¤ËÄã¥ì¥Ù¥ë I/O ¥¨¥é¡¼
242 ¤¬È¯À¸¤·¤¿¾ì¹ç¤Ë¤âµ¯¤³¤ë¡£
243 .TP
244 .B EISDIR
245 .\"O .I fd
246 .\"O refers to a directory.
247 .I fd
248 ¤¬¥Ç¥£¥ì¥¯¥È¥ê¤ò»²¾È¤·¤Æ¤¤¤ë¡£
249 .PP
250 .\"O Other errors may occur, depending on the object connected to
251 .\"O .IR fd .
252 .I fd
253 ¤¬Àܳ¤·¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤è¤Ã¤Æ¤Ï¾¤Î¥¨¥é¡¼¤âµ¯¤³¤ê¤¨¤ë¡£
254 .\"O POSIX allows a
255 .\"O .BR read ()
256 .\"O that is interrupted after reading some data
257 .\"O to return \-1 (with
258 .\"O .I errno
259 .\"O set to
260 .\"O .BR EINTR )
261 .\"O or to return the number of bytes already read.
262 POSIX ¤Ç¤Ï¡¢
263 ¤¤¤¯¤é¤«¤Î¥Ç¡¼¥¿¤òÆɤó¤À¸å¤Ë³ä¤ê¹þ¤ß¤¬µ¯¤³¤Ã¤¿¾ì¹ç¡¢
264 .BR read ()
265 ¤Ï
266 .RI ( errno
267 ¤Ë
268 .B EINTR
269 ¤òÀßÄꤷ¤Æ) \-1 ¤òÊÖ¤·¤Æ¤â¤è¤¤¤·¡¢
270 ´û¤ËÆɤ߹þ¤ó¤À¥Ð¥¤¥È¿ô¤òÊÖ¤·¤Æ¤â¤è¤¤¡£
271 .\"O .SH "CONFORMING TO"
272 .SH ½àµò
273 SVr4, 4.3BSD, POSIX.1-2001.
274 .\"O .SH NOTES
275 .SH Ãí°Õ
276 .\"O On NFS file systems, reading small amounts of data will only update the
277 .\"O timestamp the first time, subsequent calls may not do so.
278 .\"O This is caused
279 .\"O by client side attribute caching, because most if not all NFS clients
280 .\"O leave st_atime (last file access time)
281 .\"O updates to the server and client side reads satisfied from the
282 .\"O client's cache will not cause st_atime updates on the server as there are no
283 .\"O server side reads.
284 .\"O Unix semantics can be obtained by disabling client
285 .\"O side attribute caching, but in most situations this will substantially
286 .\"O increase server load and decrease performance.
287 NFS ¤Ë¤ª¤¤¤Æ¡£¾¯Î̤Υǡ¼¥¿¤òÆɤ߹þ¤à¾ì¹ç¡¢ºÇ½é¤Î»þ¤Î¤ß¤Ë¥¿¥¤¥à
288 ¥¹¥¿¥ó¥×¤¬¹¹¿·¤µ¤ì¡¢Â³¤¯¥³¡¼¥ë¤Ç¤Ï¹¹¿·¤µ¤ì¤Ê¤¤¤À¤í¤¦¡£
289 ¤³¤ì¤Ï¥¯¥é¥¤¥¢¥ó¥È¦¤Ç°À­¤Î¥­¥ã¥Ã¥·¥ó¥°¤ò¹Ô¤Ê¤¦¤¿¤á¤Ç¤¢¤ë¡£
290 ¤Ê¤¼¤Ê¤é¤Ð¡¢¤â¤·Á´¤Æ¤Î NFS ¥¯¥é¥¤¥¢¥ó¥È¤¬ st_atime (ºÇ½ª¥Õ¥¡¥¤¥ë¥¢¥¯¥»¥¹»þ¹ï)
291 ¤Î¹¹¿·¤ò¥µ¡¼¥Ð¡¼¤ËÁ÷¤é¤º¡¢¥¯¥é¥¤¥¢¥ó¥È¦¤Ç¥­¥ã¥Ã¥·¥å¤òÆɤळ¤È¤ËËþ­¤·¤Æ
292 ¤¤¤ì¤Ð¡¢¥µ¡¼¥Ð¡¼Â¦¤Ç¤Î read ¤ÏȯÀ¸¤·¤Ê¤¤¤Î¤Ç st_atime ¤Î¹¹¿·¤Ï¹Ô¤Ê¤ï¤ì¤«¤é¤À¡£
293 Unix ¤ÎÊý¼°¤Ç¤Ï¡¢¥¯¥é¥¤¥¢¥ó¥È¦¤Î°À­¤Î¥­¥ã¥Ã¥·¥ó¥°¤ò̵¸ú¤Ë¤¹¤ë¤³¤È¤Ç¡¢
294 ¤³¤ì¤òÆÀ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£¤·¤«¤·¤Û¤È¤ó¤É¤Î¾õ¶·¤Ç¤Ï¤³¤ì¤Ï³¤¯¥µ¡¼¥Ð¡¼¤Î
295 Éé²Ù¤òÁý²Ã¤µ¤»¡¢¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤ÎÄã²¼¤ò¤â¤¿¤é¤¹¡£
296 .PP
297 .\"O Many file systems and disks were considered to be fast enough that the
298 .\"O implementation of
299 .\"O .B O_NONBLOCK
300 .\"O was deemed unnecessary.
301 .\"O So,
302 .\"O .B O_NONBLOCK
303 .\"O may not be available on files
304 .\"O and/or disks.
305 ¿¤¯¤Î¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤ä¥Ç¥£¥¹¥¯¤Ï
306 .B O_NONBLOCK
307 ¤Î¼ÂÁõ¤Ï¤·¤Ê¤¯¤Æ¤âºÑ¤à¤¯¤é¤¤¤Ë½½Ê¬¤Ë¹â®¤Ç¤¢¤ë¤È¹Í¤¨¤é¤ì¤Æ¤¤¤ë¡£
308 ¤½¤ì¤Ç¤½¤Î¤è¤¦¤Ê¥Õ¥¡¥¤¥ë¤ä¥Ç¥£¥¹¥¯¤Ë¤Ï
309 .B O_NONBLOCK
310 ¤ÏÍøÍѤǤ­¤Ê¤¤¤«¤â¤·¤ì¤Ê¤¤¡£
311 .\"O .SH "SEE ALSO"
312 .SH ´ØÏ¢¹àÌÜ
313 .BR close (2),
314 .BR fcntl (2),
315 .BR ioctl (2),
316 .BR lseek (2),
317 .BR open (2),
318 .BR pread (2),
319 .BR readdir (2),
320 .BR readlink (2),
321 .BR readv (2),
322 .BR select (2),
323 .BR write (2),
324 .BR fread (3)