1 .\" Copyright (c) 1980, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
42 .Fn read "int fd" "void *buf" "size_t nbytes"
44 .Fn pread "int fd" "void *buf" "size_t nbytes" "off_t offset"
47 .Fn readv "int fd" "const struct iovec *iov" "int iovcnt"
49 .Fn preadv "int fd" "const struct iovec *iov" "int iovcnt" "off_t offset"
56 of data from the object referenced by the descriptor
58 into the buffer pointed to by
63 performs the same action, but scatters the input data
66 buffers specified by the members of the
68 array: iov[0], iov[1], ..., iov[iovcnt\|\-\|1].
74 perform the same functions, but read from the specified position in
75 the file without modifying the file pointer.
83 structure is defined as:
85 .Bd -literal -offset indent -compact
87 void *iov_base; /* Base address. */
88 size_t iov_len; /* Length. */
94 entry specifies the base address and length of an area
95 in memory where data should be placed.
99 will always fill an area completely before proceeding
102 On objects capable of seeking, the
105 given by the pointer associated with
111 the pointer is incremented by the number of bytes actually read.
113 Objects that are not capable of seeking always read from the current
115 The value of the pointer associated with such an
118 Upon successful completion,
124 return the number of bytes actually read and placed in the buffer.
125 The system guarantees to read the number of bytes requested if
126 the descriptor references a normal file that has that many bytes left
127 before the end-of-file, but in no other case.
135 syscalls are atomic with respect to each other in the effects on file
136 content, when they operate on regular files.
137 If two threads each call one of the
141 syscalls, each call will see either all of the changes of the other call,
145 kernel implements this guarantee by locking the file ranges affected by
149 number of bytes actually read is returned.
150 Upon reading end-of-file,
152 Otherwise, a -1 is returned and the global variable
154 is set to indicate the error.
169 is not a valid file or socket descriptor open for reading.
173 argument refers to a socket, and the remote socket end is
179 points outside the allocated address space.
181 An I/O error occurred while reading from the file system.
183 Corrupted data was detected while reading from the file system.
185 Failed to read from a file, e.g. /proc/<pid>/regs while <pid> is not stopped
187 A read from a slow device
188 (i.e.\& one that might block for an arbitrary amount of time)
189 was interrupted by the delivery of a signal
190 before any data arrived.
192 The pointer associated with
196 The file was marked for non-blocking I/O,
197 and no data were ready to be read.
199 The file descriptor is associated with a directory.
200 Directories may only be read directly by root if the filesystem supports it and
202 .Dv security.bsd.allow_read_dir
203 sysctl MIB is set to a non-zero value.
204 For most scenarios, the
206 function should be used instead.
208 The file descriptor is associated with a file system and file type that
209 do not allow regular read operations on it.
211 The file descriptor is associated with a regular file,
215 is before the end-of-file, and
217 is greater than or equal to the offset maximum established
218 for this file system.
230 may return one of the following errors:
236 was less than or equal to 0, or greater than
249 array overflowed a 32-bit integer.
253 array points outside the process's allocated address space.
260 system calls may also return the following errors:
267 The file descriptor is associated with a pipe, socket, or FIFO.
272 .Xr getdirentries 2 ,
283 system call is expected to conform to
289 system calls are expected to conform to
294 system call appeared in
302 system call appeared in