]>
Commit | Line | Data |
---|---|---|
fea681da MK |
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 | .TH READ 2 1997-07-12 "Linux 2.0.32" "Linux Programmer's Manual" | |
36 | .SH NAME | |
37 | read \- read from a file descriptor | |
38 | .SH SYNOPSIS | |
39 | .nf | |
40 | .B #include <unistd.h> | |
41 | .sp | |
42 | .BI "ssize_t read(int " fd ", void *" buf ", size_t " count ); | |
43 | .fi | |
44 | .SH DESCRIPTION | |
63aa9df0 | 45 | .BR read () |
fea681da MK |
46 | attempts to read up to |
47 | .I count | |
48 | bytes from file descriptor | |
49 | .I fd | |
50 | into the buffer starting at | |
51 | .IR buf . | |
52 | .PP | |
53 | If | |
54 | .I count | |
63aa9df0 | 55 | is zero, \fBread\fP() returns zero and has no other results. |
fea681da MK |
56 | If |
57 | .I count | |
58 | is greater than SSIZE_MAX, the result is unspecified. | |
59 | .PP | |
60 | .SH "RETURN VALUE" | |
61 | On success, the number of bytes read is returned (zero indicates end of | |
62 | file), and the file position is advanced by this number. | |
63 | It is not an error if this number is smaller than the number of bytes | |
64 | requested; this may happen for example because fewer bytes are actually | |
65 | available right now (maybe because we were close to end-of-file, or | |
66 | because we are reading from a pipe, or from a terminal), or because | |
63aa9df0 | 67 | \fBread\fP() was interrupted by a signal. |
fea681da MK |
68 | On error, \-1 is returned, and |
69 | .I errno | |
70 | is set appropriately. In this case it is left unspecified whether | |
71 | the file position (if any) changes. | |
72 | .SH ERRORS | |
73 | .TP | |
74 | .B EAGAIN | |
75 | Non-blocking I/O has been selected using | |
76 | .B O_NONBLOCK | |
77 | and no data was immediately available for reading. | |
78 | .TP | |
79 | .B EBADF | |
80 | .I fd | |
81 | is not a valid file descriptor or is not open for reading. | |
82 | .TP | |
83 | .B EFAULT | |
84 | .I buf | |
85 | is outside your accessible address space. | |
86 | .TP | |
87 | .B EINTR | |
88 | The call was interrupted by a signal before any data was read. | |
89 | .TP | |
90 | .B EINVAL | |
91 | .I fd | |
94604cf7 MK |
92 | is attached to an object which is unsuitable for reading; |
93 | or the file was opened with the | |
94 | .B O_DIRECT | |
95 | flag, and either the address specified in | |
96 | .IR buf , | |
97 | the value specified in | |
98 | .IR count , | |
99 | or the current file offset is not suitably aligned. | |
fea681da MK |
100 | .TP |
101 | .B EIO | |
102 | I/O error. This will happen for example when the process is in a | |
103 | background process group, tries to read from its controlling tty, | |
104 | and either it is ignoring or blocking SIGTTIN or its process group | |
105 | is orphaned. It may also occur when there is a low-level I/O error | |
106 | while reading from a disk or tape. | |
107 | .TP | |
108 | .B EISDIR | |
109 | .I fd | |
110 | refers to a directory. | |
111 | .PP | |
112 | Other errors may occur, depending on the object connected to | |
113 | .IR fd . | |
114 | POSIX allows a | |
e511ffb6 | 115 | .BR read () |
fea681da MK |
116 | that is interrupted after reading some data |
117 | to return \-1 (with | |
118 | .I errno | |
119 | set to EINTR) or to return the number of bytes already read. | |
120 | .SH "CONFORMING TO" | |
b14d4aa5 | 121 | SVr4, SVID, AT&T, POSIX, X/OPEN, 4.3BSD |
fea681da MK |
122 | .SH RESTRICTIONS |
123 | On NFS file systems, reading small amounts of data will only update the | |
124 | time stamp the first time, subsequent calls may not do so. This is caused | |
125 | by client side attribute caching, because most if not all NFS clients | |
310b7919 MK |
126 | leave st_atime (last file access time) |
127 | updates to the server and client side reads satisfied from the | |
128 | client's cache will not cause st_atime updates on the server as there are no | |
fea681da MK |
129 | server side reads. UNIX semantics can be obtained by disabling client |
130 | side attribute caching, but in most situations this will substantially | |
131 | increase server load and decrease performance. | |
132 | .PP | |
133 | Many filesystems and disks were considered to be fast enough that the | |
134 | implementation of | |
135 | .B O_NONBLOCK | |
136 | was deemed unneccesary. So, O_NONBLOCK may not be available on files | |
137 | and/or disks. | |
138 | .SH "SEE ALSO" | |
139 | .BR close (2), | |
140 | .BR fcntl (2), | |
141 | .BR ioctl (2), | |
142 | .BR lseek (2), | |
94604cf7 | 143 | .BR open (2), |
fea681da MK |
144 | .BR readdir (2), |
145 | .BR readlink (2), | |
146 | .BR select (2), | |
147 | .BR write (2), | |
148 | .BR fread (3), | |
149 | .BR readv (3) |