1read(2) System Calls Manual read(2)
2
3
4
6 read - read from a file descriptor
7
9 Standard C library (libc, -lc)
10
12 #include <unistd.h>
13
14 ssize_t read(int fd, void buf[.count], size_t count);
15
17 read() attempts to read up to count bytes from file descriptor fd into
18 the buffer starting at buf.
19
20 On files that support seeking, the read operation commences at the file
21 offset, and the file offset is incremented by the number of bytes read.
22 If the file offset is at or past the end of file, no bytes are read,
23 and read() returns zero.
24
25 If count is zero, read() may detect the errors described below. In the
26 absence of any errors, or if read() does not check for errors, a read()
27 with a count of 0 returns zero and has no other effects.
28
29 According to POSIX.1, if count is greater than SSIZE_MAX, the result is
30 implementation-defined; see NOTES for the upper limit on Linux.
31
33 On success, the number of bytes read is returned (zero indicates end of
34 file), and the file position is advanced by this number. It is not an
35 error if this number is smaller than the number of bytes requested;
36 this may happen for example because fewer bytes are actually available
37 right now (maybe because we were close to end-of-file, or because we
38 are reading from a pipe, or from a terminal), or because read() was in‐
39 terrupted by a signal. See also NOTES.
40
41 On error, -1 is returned, and errno is set to indicate the error. In
42 this case, it is left unspecified whether the file position (if any)
43 changes.
44
46 EAGAIN The file descriptor fd refers to a file other than a socket and
47 has been marked nonblocking (O_NONBLOCK), and the read would
48 block. See open(2) for further details on the O_NONBLOCK flag.
49
50 EAGAIN or EWOULDBLOCK
51 The file descriptor fd refers to a socket and has been marked
52 nonblocking (O_NONBLOCK), and the read would block.
53 POSIX.1-2001 allows either error to be returned for this case,
54 and does not require these constants to have the same value, so
55 a portable application should check for both possibilities.
56
57 EBADF fd is not a valid file descriptor or is not open for reading.
58
59 EFAULT buf is outside your accessible address space.
60
61 EINTR The call was interrupted by a signal before any data was read;
62 see signal(7).
63
64 EINVAL fd is attached to an object which is unsuitable for reading; or
65 the file was opened with the O_DIRECT flag, and either the ad‐
66 dress specified in buf, the value specified in count, or the
6