1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\" 1993 Michael Haardt, Ian Jackson.
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.
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.
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
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
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>
35 .TH READ 2 1997-07-12 "Linux" "Linux Programmer's Manual"
37 read \- read from a file descriptor
40 .B #include <unistd.h>
42 .BI "ssize_t read(int " fd ", void *" buf ", size_t " count );
46 attempts to read up to
48 bytes from file descriptor
50 into the buffer starting at
57 returns zero and has no other results.
60 is greater than SSIZE_MAX, the result is unspecified.
62 On success, the number of bytes read is returned (zero indicates end of
63 file), and the file position is advanced by this number.
64 It is not an error if this number is smaller than the number of bytes
65 requested; this may happen for example because fewer bytes are actually
66 available right now (maybe because we were close to end-of-file, or
67 because we are reading from a pipe, or from a terminal), or because
69 was interrupted by a signal.
70 On error, \-1 is returned, and
73 In this case it is left unspecified whether
74 the file position (if any) changes.
78 Non-blocking I/O has been selected using
80 and no data was immediately available for reading.
84 is not a valid file descriptor or is not open for reading.
88 is outside your accessible address space.
91 The call was interrupted by a signal before any data was read.
95 is attached to an object which is unsuitable for reading;
96 or the file was opened with the
98 flag, and either the address specified in
100 the value specified in
102 or the current file offset is not suitably aligned.
106 This will happen for example when the process is in a
107 background process group, tries to read from its controlling tty,
108 and either it is ignoring or blocking SIGTTIN or its process group
110 It may also occur when there is a low-level I/O error
111 while reading from a disk or tape.
115 refers to a directory.
117 Other errors may occur, depending on the object connected to
121 that is interrupted after reading some data
124 set to EINTR) or to return the number of bytes already read.
126 SVr4, 4.3BSD, POSIX.1-2001.
128 On NFS file systems, reading small amounts of data will only update the
129 time stamp the first time, subsequent calls may not do so.
131 by client side attribute caching, because most if not all NFS clients
132 leave st_atime (last file access time)
133 updates to the server and client side reads satisfied from the
134 client's cache will not cause st_atime updates on the server as there are no
136 UNIX semantics can be obtained by disabling client
137 side attribute caching, but in most situations this will substantially
138 increase server load and decrease performance.
140 Many filesystems and disks were considered to be fast enough that the
143 was deemed unnecessary.
144 So, O_NONBLOCK may not be available on files