world - Document extpread() and extpwrite()
[dragonfly.git] / lib / libc / sys / read.2
blob4b6d850aa4d9960802cfdf0a20fcd26750880b15
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. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)read.2      8.4 (Berkeley) 2/26/94
29 .\" $FreeBSD: src/lib/libc/sys/read.2,v 1.9.2.6 2001/12/14 18:34:01 ru Exp $
30 .\" $DragonFly: src/lib/libc/sys/read.2,v 1.5 2006/04/27 16:01:33 swildner Exp $
31 .\"
32 .Dd April 27, 2006
33 .Dt READ 2
34 .Os
35 .Sh NAME
36 .Nm read ,
37 .Nm readv ,
38 .Nm pread ,
39 .Nm preadv ,
40 .Nm extpread ,
41 .Nm extpreadv
42 .Nd read input
43 .Sh LIBRARY
44 .Lb libc
45 .Sh SYNOPSIS
46 .In sys/types.h
47 .In sys/uio.h
48 .In unistd.h
49 .Ft ssize_t
50 .Fn read "int d" "void *buf" "size_t nbytes"
51 .Ft ssize_t
52 .Fn readv "int d" "const struct iovec *iov" "int iovcnt"
53 .Ft ssize_t
54 .Fn pread "int d" "void *buf" "size_t nbytes" "off_t offset"
55 .Ft ssize_t
56 .Fn preadv "int d" "const struct iovec *iov" "int iovcnt" "off_t offset"
57 .Ft ssize_t
58 .Fn extpread "int d" "void *buf" "size_t nbytes" "int flags" "off_t offset"
59 .Ft ssize_t
60 .Fn extpreadv "int d" "const struct iovec *iov" "int iovcnt" "int flags" "off_t offset"
61 .Sh DESCRIPTION
62 .Fn Read
63 attempts to read
64 .Fa nbytes
65 of data from the object referenced by the descriptor
66 .Fa d
67 into the buffer pointed to by
68 .Fa buf .
69 .Fn Readv
70 performs the same action, but scatters the input data
71 into the
72 .Fa iovcnt
73 buffers specified by the members of the
74 .Fa iov
75 array: iov[0], iov[1], ..., iov[iovcnt\|\-\|1].
76 The
77 .Fn pread ,
78 .Fn preadv ,
79 .Fn extpread ,
80 and
81 .Fn extpreadv
82 calls perform the same function, but read from the specified position in
83 the file without modifying the file pointer.
84 .Pp
85 For
86 .Fn readv
87 and
88 .Fn preadv ,
89 the
90 .Fa iovec
91 structure is defined as:
92 .Pp
93 .Bd -literal -offset indent -compact
94 struct iovec {
95         char   *iov_base;  /* Base address. */
96         size_t iov_len;    /* Length. */
98 .Ed
99 .Pp
100 Each
101 .Fa iovec
102 entry specifies the base address and length of an area
103 in memory where data should be placed.
104 .Fn Readv
106 .Fn preadv
107 will always fill an area completely before proceeding
108 to the next.
111 .Fn extpread
113 .Fn extpreadv
114 functions are
116 specific
117 and extend the specification further by allowing a flags argument
118 to also be passed in, controlling blocking/non-blocking and other features
119 on a call-by-call basis, ignoring the related default for the descriptor.
120 Allowed flags are:
121 .Bl -tag -width Er
122 .It O_FBLOCKING
123 Force the system call to operate in a blocking fashion.
124 .It O_FNONBLOCKING
125 Force the system call to operate in a non-blocking fashion.
126 .It O_FAPPEND
127 Force append mode for the operation.
128 .It O_FOFFSET
129 Force offset mode for the operation.
130 .It O_FSYNCWRITE
131 (ignored for reads)
132 .It O_FASYNCWRITE
133 (ignored for reads)
136 On objects capable of seeking, the
137 .Fn read
138 starts at a position
139 given by the pointer associated with
140 .Fa d
141 (see
142 .Xr lseek 2 ) .
143 Upon return from
144 .Fn read ,
145 the pointer is incremented by the number of bytes actually read.
147 Objects that are not capable of seeking always read from the current
148 position.  The value of the pointer associated with such an
149 object is undefined.
151 Upon successful completion,
152 .Fn read ,
153 .Fn readv ,
154 .Fn pread ,
156 .Fn preadv
157 return the number of bytes actually read and placed in the buffer.
158 The system guarantees to read the number of bytes requested if
159 the descriptor references a normal file that has that many bytes left
160 before the end-of-file, but in no other case.
161 .Sh RETURN VALUES
162 If successful, the
163 number of bytes actually read is returned.
164 Upon reading end-of-file,
165 zero is returned.
166 Otherwise, a -1 is returned and the global variable
167 .Va errno
168 is set to indicate the error.
169 .Sh ERRORS
170 .Fn Read ,
171 .Fn readv ,
172 .Fn pread ,
174 .Fn preadv
175 will succeed unless:
176 .Bl -tag -width Er
177 .It Bq Er EBADF
178 .Fa D
179 is not a valid file or socket descriptor open for reading.
180 .It Bq Er EFAULT
181 .Fa Buf
182 points outside the allocated address space.
183 .It Bq Er EIO
184 An I/O error occurred while reading from the file system.
185 .It Bq Er EINTR
186 A read from a slow device was interrupted before
187 any data arrived by the delivery of a signal.
188 .It Bq Er EINVAL
189 The pointer associated with
190 .Fa d
191 was negative.
192 .It Bq Er EAGAIN
193 The file was marked for non-blocking I/O,
194 and no data were ready to be read.
197 In addition,
198 .Fn readv
200 .Fn preadv
201 may return one of the following errors:
202 .Bl -tag -width Er
203 .It Bq Er EINVAL
204 .Fa Iovcnt
205 was less than or equal to 0, or greater than 16.
206 .It Bq Er EINVAL
207 One of the
208 .Fa iov_len
209 values in the
210 .Fa iov
211 array was negative.
212 .It Bq Er EINVAL
213 The sum of the
214 .Fa iov_len
215 values in the
216 .Fa iov
217 array overflowed a 32-bit integer.
218 .It Bq Er EFAULT
219 Part of the
220 .Fa iov
221 points outside the process's allocated address space.
225 .Fn pread
227 .Fn preadv
228 calls may also return the following errors:
229 .Bl -tag -width Er
230 .It Bq Er EINVAL
231 The specified file offset is invalid.
232 .It Bq Er ESPIPE
233 The file descriptor is associated with a pipe, socket, or FIFO.
235 .Sh SEE ALSO
236 .Xr dup 2 ,
237 .Xr fcntl 2 ,
238 .Xr open 2 ,
239 .Xr pipe 2 ,
240 .Xr select 2 ,
241 .Xr socket 2 ,
242 .Xr socketpair 2
243 .Sh STANDARDS
245 .Fn read
246 function call is expected to conform to
247 .St -p1003.1-90 .
249 .Fn readv
251 .Fn pread
252 functions are expected to conform to
253 .St -xpg4.2 .
254 .Sh HISTORY
256 .Fn preadv
257 function call was added in
258 .Dx 1.5 .
260 .Fn pread
261 function call
262 appeared in
263 .At V.4 .
265 .Fn readv
266 function call
267 appeared in
268 .Bx 4.2 .
270 .Fn read
271 function call appeared in
272 .At v6 .