OSDN Git Service

14732a4d488b61847131d2db20d3ec864bea42fd
[linuxjm/LDP_man-pages.git] / 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)