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 cur‐
18       rent  file  offset, and the file offset is incremented by the number of
19       bytes read.  If the current file offset is at or past the end of  file,
20       no bytes are read, 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       If count is greater than SSIZE_MAX, the result is unspecified.
27

RETURN VALUE

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

ERRORS

40       EAGAIN The  file descriptor fd refers to a file other than a socket and
41              has been marked nonblocking (O_NONBLOCK),  and  the  read  would
42              block.
43
44       EAGAIN or EWOULDBLOCK
45              The  file  descriptor  fd refers to a socket and has been marked
46              nonblocking   (O_NONBLOCK),   and   the   read   would    block.
47              POSIX.1-2001  allows  either error to be returned for this case,
48              and does not require these constants to have the same value,  so
49              a portable application should check for both possibilities.
50
51       EBADF  fd is not a valid file descriptor or is not open for reading.
52
53       EFAULT buf is outside your accessible address space.
54
55       EINTR  The  call  was interrupted by a signal before any data was read;
56              see signal(7).
57
58       EINVAL fd is attached to an object which is unsuitable for reading;  or
59              the  file  was  opened  with  the  O_DIRECT flag, and either the
60              address specified in buf, the value specified in count,  or  the
61              current file offset is not suitably aligned.
62
63       EINVAL fd  was  created  via  a call to timerfd_create(2) and the wrong
64              size buffer was given to read(); see timerfd_create(2) for  fur‐
65              ther information.
66
67       EIO    I/O  error.  This will happen for example when the process is in
68              a background process group, tries to read from  its  controlling
69              terminal,  and  either it is ignoring or blocking SIGTTIN or its
70              process group is orphaned.  It may also occur when  there  is  a
71              low-level I/O error while reading from a disk or tape.
72
73       EISDIR fd refers to a directory.
74
75       Other errors may occur, depending on the object connected to fd.  POSIX
76       allows a read() that is interrupted after reading some data  to  return
77       -1  (with  errno set to EINTR) or to return the number of bytes already
78       read.
79

CONFORMING TO

81       SVr4, 4.3BSD, POSIX.1-2001.
82

NOTES

84       On NFS file systems, reading small amounts  of  data  will  update  the
85       timestamp only the first time, subsequent calls may not do so.  This is
86       caused by client side attribute caching, because most if  not  all  NFS
87       clients  leave  st_atime  (last file access time) updates to the server
88       and client side reads satisfied from the client's cache will not  cause
89       st_atime updates on the server as there are no server side reads.  UNIX
90       semantics can be obtained by disabling client side  attribute  caching,
91       but in most situations this will substantially increase server load and
92       decrease performance.
93

SEE ALSO

95       close(2), fcntl(2), ioctl(2), lseek(2), open(2), pread(2),  readdir(2),
96       readlink(2), readv(2), select(2), write(2), fread(3)
97

COLOPHON

99       This  page  is  part of release 3.53 of the Linux man-pages project.  A
100       description of the project, and information about reporting  bugs,  can
101       be found at http://www.kernel.org/doc/man-pages/.
102
103
104
105Linux                             2013-02-12                           READ(2)
Impressum