2 read - read from a file descriptor
5 ssize_t read(int fd, void *buf, size_t count);
8 read() attempts to read up to count bytes from file
9 descriptor fd into the buffer starting at buf.
11 If count is zero, read() returns zero and has no other
16 On success, the number of bytes read is returned (zero
17 indicates end of file), and the file position is advanced
18 by this number. It is not an error if this number is
19 smaller than the number of bytes requested; this may hap-
20 pen for example because fewer bytes are actually available
21 right now (maybe because we were close to end-of-file, or
22 because we are reading from a pipe, or from a terminal),
23 or because read() was interrupted by a signal. On error,
24 -1 is returned, and errno is set appropriately. In this
25 case it is left unspecified whether the file position (if
29 EINTR The call was interrupted by a signal before any
32 EAGAIN Non-blocking I/O has been selected using O_NON-
33 BLOCK and no data was immediately available for
36 EIO I/O error. This will happen for example when the
37 process is in a background process group, tries to
38 read from its controlling tty, and either it is
39 ignoring or blocking SIGTTIN or its process group
40 is orphaned. It may also occur when there is a
41 low-level I/O error while reading from a disk or
44 EISDIR fd refers to a directory.
46 EBADF fd is not a valid file descriptor or is not open
49 EINVAL fd is attached to an object which is unsuitable
52 Other errors may occur, depending on the object connected
53 to fd. POSIX allows a read that is interrupted after
54 reading some data to return -1 (with errno set to EINTR)
55 or to return the number of bytes already read.