1READ(2)                       System Calls Manual                      READ(2)
2
3
4

NAME

6       read, readv - read input
7

SYNOPSIS

9       cc = read(d, buf, nbytes)
10       int cc, d;
11       char *buf;
12       unsigned short nbytes;
13
14       #include <sys/types.h>
15       #include <sys/uio.h>
16
17       cc = readv(d, iov, iovcnt)
18       int cc, d;
19       struct iovec *iov;
20       int iovcnt;
21

DESCRIPTION

23       Read  attempts to read nbytes of data from the object referenced by the
24       descriptor d into the buffer pointed to by  buf.   Readv  performs  the
25       same action, but scatters the input data into the iovcnt buffers speci‐
26       fied  by  the  members  of  the  iov  array:   iov[0],   iov[1],   ...,
27       iov[iovcnt-1].
28
29       For readv, the iovec structure is defined as
30
31              struct iovec {
32                   caddr_t   iov_base;
33                   u_short   iov_len;
34              };
35
36       Each  iovec  entry  specifies the base address and length of an area in
37       memory where data should be placed.  Readv will  always  fill  an  area
38       completely before proceeding to the next.
39
40       On  objects  capable of seeking, the read starts at a position given by
41       the pointer associated with d (see lseek(2)).  Upon return  from  read,
42       the pointer is incremented by the number of bytes actually read.
43
44       Objects  that  are  not capable of seeking always read from the current
45       position.  The value of the pointer associated with such an  object  is
46       undefined.
47
48       Upon  successful  completion, read and readv return the number of bytes
49       actually read and placed in the buffer.  The system guarantees to  read
50       the  number  of  bytes  requested if the descriptor references a normal
51       file that has that many bytes left before the end-of-file,  but  in  no
52       other case.
53
54       If the returned value is 0, then end-of-file has been reached.
55

RETURN VALUE

57       If  successful,  the number of bytes actually read is returned.  Other‐
58       wise, a -1 is returned and the global variable errno is set to indicate
59       the error.
60

ERRORS

62       Read and readv will fail if one or more of the following are true:
63
64       [EBADF]        D  is  not  a  valid  file or socket descriptor open for
65                      reading.
66
67       [EFAULT]       Buf points outside the allocated address space.
68
69       [EIO]          An I/O error occurred while reading from the  file  sys‐
70                      tem.
71
72       [EINTR]        A  read  from  a  slow device was interrupted before any
73                      data arrived by the delivery of a signal.
74
75       [EINVAL]       The pointer associated with d was negative.
76
77       [EWOULDBLOCK]  The file was marked for non-blocking I/O,  and  no  data
78                      were ready to be read.
79
80       In addition, readv may return one of the following errors:
81
82       [EINVAL]       Iovcnt was less than or equal to 0, or greater than 16.
83
84       [EINVAL]       The  sum  of  the  iov_len values in the iov array over‐
85                      flowed a short.
86
87       [EFAULT]       Part of the iov points outside the  process's  allocated
88                      address space.
89

SEE ALSO

91       dup(2), fcntl(2), open(2), pipe(2), select(2), socket(2), socketpair(2)
92
93
94
954th Berkeley Distribution       August 1, 1987                         READ(2)
Impressum