Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / libc / sys / read.2
1 .\" Copyright (c) 1980, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)read.2      8.4 (Berkeley) 2/26/94
33 .\" $FreeBSD: src/lib/libc/sys/read.2,v 1.9.2.6 2001/12/14 18:34:01 ru Exp $
34 .\" $DragonFly: src/lib/libc/sys/read.2,v 1.2 2003/06/17 04:26:47 dillon Exp $
35 .\"
36 .Dd February 26, 1994
37 .Dt READ 2
38 .Os
39 .Sh NAME
40 .Nm read ,
41 .Nm readv ,
42 .Nm pread
43 .Nd read input
44 .Sh LIBRARY
45 .Lb libc
46 .Sh SYNOPSIS
47 .In sys/types.h
48 .In sys/uio.h
49 .In unistd.h
50 .Ft ssize_t
51 .Fn read "int d" "void *buf" "size_t nbytes"
52 .Ft ssize_t
53 .Fn readv "int d" "const struct iovec *iov" "int iovcnt"
54 .Ft ssize_t
55 .Fn pread "int d" "void *buf" "size_t nbytes" "off_t offset"
56 .Sh DESCRIPTION
57 .Fn Read
58 attempts to read
59 .Fa nbytes
60 of data from the object referenced by the descriptor
61 .Fa d
62 into the buffer pointed to by
63 .Fa buf .
64 .Fn Readv
65 performs the same action, but scatters the input data
66 into the
67 .Fa iovcnt
68 buffers specified by the members of the
69 .Fa iov
70 array: iov[0], iov[1], ..., iov[iovcnt\|\-\|1].
71 .Fn Pread
72 performs the same function, but reads from the specified position in
73 the file without modifying the file pointer.
74 .Pp
75 For
76 .Fn readv ,
77 the
78 .Fa iovec
79 structure is defined as:
80 .Pp
81 .Bd -literal -offset indent -compact
82 struct iovec {
83         char   *iov_base;  /* Base address. */
84         size_t iov_len;    /* Length. */
85 };
86 .Ed
87 .Pp
88 Each
89 .Fa iovec
90 entry specifies the base address and length of an area
91 in memory where data should be placed.
92 .Fn Readv
93 will always fill an area completely before proceeding
94 to the next.
95 .Pp
96 On objects capable of seeking, the
97 .Fn read
98 starts at a position
99 given by the pointer associated with
100 .Fa d
101 (see
102 .Xr lseek 2 ) .
103 Upon return from
104 .Fn read ,
105 the pointer is incremented by the number of bytes actually read.
106 .Pp
107 Objects that are not capable of seeking always read from the current
108 position.  The value of the pointer associated with such an
109 object is undefined.
110 .Pp
111 Upon successful completion,
112 .Fn read ,
113 .Fn readv ,
114 and
115 .Fn pread
116 return the number of bytes actually read and placed in the buffer.
117 The system guarantees to read the number of bytes requested if
118 the descriptor references a normal file that has that many bytes left
119 before the end-of-file, but in no other case.
120 .Sh RETURN VALUES
121 If successful, the
122 number of bytes actually read is returned.
123 Upon reading end-of-file,
124 zero is returned.
125 Otherwise, a -1 is returned and the global variable
126 .Va errno
127 is set to indicate the error.
128 .Sh ERRORS
129 .Fn Read ,
130 .Fn readv ,
131 and
132 .Fn pread
133 will succeed unless:
134 .Bl -tag -width Er
135 .It Bq Er EBADF
136 .Fa D
137 is not a valid file or socket descriptor open for reading.
138 .It Bq Er EFAULT
139 .Fa Buf
140 points outside the allocated address space.
141 .It Bq Er EIO
142 An I/O error occurred while reading from the file system.
143 .It Bq Er EINTR
144 A read from a slow device was interrupted before
145 any data arrived by the delivery of a signal.
146 .It Bq Er EINVAL
147 The pointer associated with
148 .Fa d
149 was negative.
150 .It Bq Er EAGAIN
151 The file was marked for non-blocking I/O,
152 and no data were ready to be read.
153 .El
154 .Pp
155 In addition,
156 .Fn readv
157 may return one of the following errors:
158 .Bl -tag -width Er
159 .It Bq Er EINVAL
160 .Fa Iovcnt
161 was less than or equal to 0, or greater than 16.
162 .It Bq Er EINVAL
163 One of the
164 .Fa iov_len
165 values in the
166 .Fa iov
167 array was negative.
168 .It Bq Er EINVAL
169 The sum of the
170 .Fa iov_len
171 values in the
172 .Fa iov
173 array overflowed a 32-bit integer.
174 .It Bq Er EFAULT
175 Part of the
176 .Fa iov
177 points outside the process's allocated address space.
178 .El
179 .Pp
180 The
181 .Fn pread
182 call may also return the following errors:
183 .Bl -tag -width Er
184 .It Bq Er EINVAL
185 The specified file offset is invalid.
186 .It Bq Er ESPIPE
187 The file descriptor is associated with a pipe, socket, or FIFO.
188 .El
189 .Sh SEE ALSO
190 .Xr dup 2 ,
191 .Xr fcntl 2 ,
192 .Xr open 2 ,
193 .Xr pipe 2 ,
194 .Xr select 2 ,
195 .Xr socket 2 ,
196 .Xr socketpair 2
197 .Sh STANDARDS
198 The
199 .Fn read
200 function call is expected to conform to
201 .St -p1003.1-90 .
202 The
203 .Fn readv
204 and
205 .Fn pread
206 functions are expected to conform to
207 .St -xpg4.2 .
208 .Sh HISTORY
209 The
210 .Fn pread
211 function call
212 appeared in
213 .At V.4 .
214 The
215 .Fn readv
216 function call
217 appeared in
218 .Bx 4.2 .
219 A
220 .Fn read
221 function call appeared in
222 .At v6 .