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       If count is zero, read() returns zero and has  no  other  results.   If
18       count is greater than SSIZE_MAX, the result is unspecified.
19

RETURN VALUE

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

ERRORS

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

CONFORMING TO

73       SVr4, 4.3BSD, POSIX.1-2001.
74

NOTES

76       On NFS file systems, reading small amounts of data will only update the
77       timestamp  the  first  time,  subsequent  calls may not do so.  This is
78       caused by client side attribute caching, because most if  not  all  NFS
79       clients  leave  st_atime  (last file access time) updates to the server
80       and client side reads satisfied from the client's cache will not  cause
81       st_atime updates on the server as there are no server side reads.  Unix
82       semantics can be obtained by disabling client side  attribute  caching,
83       but in most situations this will substantially increase server load and
84       decrease performance.
85
86       Many file systems and disks were considered to be fast enough that  the
87       implementation  of  O_NONBLOCK  was deemed unnecessary.  So, O_NONBLOCK
88       may not be available on files and/or disks.
89

SEE ALSO

91       close(2), fcntl(2), ioctl(2), lseek(2), open(2), pread(2),  readdir(2),
92       readlink(2), readv(2), select(2), write(2), fread(3)
93

COLOPHON

95       This  page  is  part of release 3.25 of the Linux man-pages project.  A
96       description of the project, and information about reporting  bugs,  can
97       be found at http://www.kernel.org/doc/man-pages/.
98
99
100
101Linux                             2009-02-23                           READ(2)
Impressum