1READ(2)                    Linux Programmer's Manual                   READ(2)
2
3
4

NAME

6       read - read from a file descriptor
7

SYNOPSIS

9       #include <unistd.h>
10
11       ssize_t read(int fd, void *buf, size_t count);
12

DESCRIPTION

14       read()  attempts to read up to count bytes from file descriptor fd into
15       the buffer starting at buf.
16
17       On files that support seeking, the read operation commences at the file
18       offset, and the file offset is incremented by the number of bytes read.
19       If the file offset is at or past the end of file, no  bytes  are  read,
20       and read() returns zero.
21
22       If count is zero, read() may detect the errors described below.  In the
23       absence of any errors, or if read() does not check for errors, a read()
24       with a count of 0 returns zero and has no other effects.
25
26       According to POSIX.1, if count is greater than SSIZE_MAX, the result is
27       implementation-defined; see NOTES for the upper limit on Linux.
28

RETURN VALUE

30       On success, the number of bytes read is returned (zero indicates end of
31       file),  and the file position is advanced by this number.  It is not an
32       error if this number is smaller than the  number  of  bytes  requested;
33       this  may happen for example because fewer bytes are actually available
34       right now (maybe because we were close to end-of-file,  or  because  we
35       are reading from a pipe, or from a terminal), or because read() was in‐
36       terrupted by a signal.  See also NOTES.
37
38       On error, -1 is returned, and errno is set to indicate the  error.   In
39       this  case,  it  is left unspecified whether the file position (if any)
40       changes.
41

ERRORS

43       EAGAIN The file descriptor fd refers to a file other than a socket  and
44              has  been  marked  nonblocking  (O_NONBLOCK), and the read would
45              block.  See open(2) for further details on the O_NONBLOCK flag.
46
47       EAGAIN or EWOULDBLOCK
48              The file descriptor fd refers to a socket and  has  been  marked
49              nonblocking    (O_NONBLOCK),   and   the   read   would   block.
50              POSIX.1-2001 allows either error to be returned for  this  case,
51              and  does not require these constants to have the same value, so
52              a portable application should check for both possibilities.
53
54       EBADF  fd is not a valid file descriptor or is not open for reading.
55
56       EFAULT buf is outside your accessible address space.
57
58       EINTR  The call was interrupted by a signal before any data  was  read;
59              see signal(7).
60
61       EINVAL fd  is attached to an object which is unsuitable for reading; or
62              the file was opened with the O_DIRECT flag, and either  the  ad‐
63              dress  specified  in  buf,  the value specified in count, or the
64              file offset is not suitably aligned.
65
66       EINVAL fd was created via a call to