fix copyright and condition notice for new sccs include
[unix-history] / usr / src / lib / libc / sys / read.2
CommitLineData
e02f9a7b
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
3e664f4b 5.\" @(#)read.2 6.6 (Berkeley) %G%
e02f9a7b 6.\"
4b664abe 7.TH READ 2 ""
e02f9a7b
KM
8.UC 4
9.SH NAME
a7ae7183 10read, readv \- read input
e02f9a7b
KM
11.SH SYNOPSIS
12.nf
a7ae7183
KM
13.ft B
14cc = read(d, buf, nbytes)
15int cc, d;
16char *buf;
17int nbytes;
18.PP
19.ft B
20#include <sys/types.h>
21#include <sys/uio.h>
22.PP
23.ft B
24cc = readv(d, iov, iovcnt)
25int cc, d;
26struct iovec *iov;
27int iovcnt;
e02f9a7b
KM
28.fi
29.SH DESCRIPTION
a7ae7183
KM
30.I Read
31attempts to read
e02f9a7b 32.I nbytes
a7ae7183
KM
33of data from the object referenced by the descriptor
34.I d
35into the buffer pointed to by
36.IR buf .
37.I Readv
38performs the same action, but scatters the input data
39into the
40.I iovcnt
41buffers specified by the members of the
d1c0365c 42.I iov
a7ae7183 43array: iov[0], iov[1], ..., iov[iovcnt\|\-\|1].
e02f9a7b 44.PP
a7ae7183
KM
45For
46.IR readv ,
47the
48.I iovec
49structure is defined as
e02f9a7b 50.PP
a7ae7183
KM
51.nf
52.RS
53.DT
54struct iovec {
55 caddr_t iov_base;
56 int iov_len;
57};
58.RE
59.fi
e02f9a7b 60.PP
a7ae7183
KM
61Each
62.I iovec
63entry specifies the base address and length of an area
64in memory where data should be placed.
65.I Readv
66will always fill an area completely before proceeding
67to the next.
68.PP
69On objects capable of seeking, the
e02f9a7b 70.I read
a7ae7183
KM
71starts at a position
72given by the pointer associated with
3e664f4b
KD
73.IR d
74(see
75.IR lseek (2)).
a7ae7183
KM
76Upon return from
77.IR read ,
78the pointer is incremented by the number of bytes actually read.
79.PP
80Objects that are not capable of seeking always read from the current
d1c0365c 81position. The value of the pointer associated with such an
a7ae7183 82object is undefined.
e02f9a7b 83.PP
a7ae7183 84Upon successful completion,
e02f9a7b 85.I read
a7ae7183
KM
86and
87.I readv
88return the number of bytes actually read and placed in the buffer.
89The system guarantees to read the number of bytes requested if
15fa213a
MK
90the descriptor references a normal file that has that many bytes left
91before the end-of-file, but in no other case.
a7ae7183
KM
92.PP
93If the returned value is 0, then
94end-of-file has been reached.
95.SH "RETURN VALUE
96If successful, the
97number of bytes actually read is returned.
98Otherwise, a \-1 is returned and the global variable
99.I errno
100is set to indicate the error.
101.SH "ERRORS
102.I Read
103and
104.I readv
105will fail if one or more of the following are true:
106.TP 15
107[EBADF]
4b664abe 108\fID\fP is not a valid file or socket descriptor open for reading.
a7ae7183
KM
109.TP 15
110[EFAULT]
111\fIBuf\fP points outside the allocated address space.
112.TP 15
fd690c8b
KM
113[EIO]
114An I/O error occurred while reading from the file system.
115.TP 15
a7ae7183
KM
116[EINTR]
117A read from a slow device was interrupted before
118any data arrived by the delivery of a signal.
d1c0365c
JL
119.TP 15
120[EINVAL]
121The pointer associated with
122.I d
123was negative.
15fa213a
MK
124.TP 15
125[EWOULDBLOCK]
126The file was marked for non-blocking I/O,
127and no data were ready to be read.
a7ae7183
KM
128.PP
129In addition,
130.I readv
131may return one of the following errors:
132.TP 15
133[EINVAL]
134.I Iovcnt
135was less than or equal to 0, or greater than 16.
136.TP 15
137[EINVAL]
138One of the
139.I iov_len
140values in the
141.I iov
142array was negative.
143.TP 15
144[EINVAL]
145The sum of the
146.I iov_len
147values in the
148.I iov
149array overflowed a 32-bit integer.
fd690c8b
KM
150.TP 15
151[EFAULT]
152Part of the \fIiov\fP points outside the process's allocated address space.
a7ae7183 153.SH "SEE ALSO"
15fa213a 154dup(2), fcntl(2), open(2), pipe(2), select(2), socket(2), socketpair(2)