mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-11-18 19:09:31 +00:00
192 lines
5.1 KiB
Groff
192 lines
5.1 KiB
Groff
|
.\" Copyright (c) 1980, 1991, 1993
|
||
|
.\" The Regents of the University of California. All rights reserved.
|
||
|
.\"
|
||
|
.\" Redistribution and use in source and binary forms, with or without
|
||
|
.\" modification, are permitted provided that the following conditions
|
||
|
.\" are met:
|
||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||
|
.\" notice, this list of conditions and the following disclaimer.
|
||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||
|
.\" documentation and/or other materials provided with the distribution.
|
||
|
.\" 3. All advertising materials mentioning features or use of this software
|
||
|
.\" must display the following acknowledgement:
|
||
|
.\" This product includes software developed by the University of
|
||
|
.\" California, Berkeley and its contributors.
|
||
|
.\" 4. Neither the name of the University nor the names of its contributors
|
||
|
.\" may be used to endorse or promote products derived from this software
|
||
|
.\" without specific prior written permission.
|
||
|
.\"
|
||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||
|
.\" SUCH DAMAGE.
|
||
|
.\"
|
||
|
.\" @(#)read.2 8.4 (Berkeley) 2/26/94
|
||
|
.\"
|
||
|
.TH READ 2 "23 January 1997" GNO "System Calls"
|
||
|
.SH NAME
|
||
|
.BR read ,
|
||
|
.BR readv
|
||
|
\- read input
|
||
|
.SH SYNOPSIS
|
||
|
#include <sys/types.h>
|
||
|
.br
|
||
|
#include <sys/uio.h>
|
||
|
.br
|
||
|
#include <unistd.h>
|
||
|
.sp 1
|
||
|
ssize_t
|
||
|
\fBread\fR (int \fId\fR, void *\fIbuf\fR, size_t \fInbytes\fR);
|
||
|
.sp 1
|
||
|
ssize_t
|
||
|
\fBreadv\fR (int \fId\fR, const struct iovec *\fIiov\fR, int \fIiovcnt\fR);
|
||
|
.SH DESCRIPTION
|
||
|
.BR read
|
||
|
attempts to read
|
||
|
.I nbytes
|
||
|
of data from the object referenced by the descriptor
|
||
|
.I d
|
||
|
into the buffer pointed to by
|
||
|
.IR buf .
|
||
|
.BR readv
|
||
|
performs the same action, but scatters the input data
|
||
|
into the
|
||
|
.I iovcnt
|
||
|
buffers specified by the members of the
|
||
|
.I iov
|
||
|
array: iov[0], iov[1], ..., iov[iovcnt\|\-\|1].
|
||
|
.LP
|
||
|
For
|
||
|
.BR readv ,
|
||
|
the
|
||
|
.I iovec
|
||
|
structure is defined as:
|
||
|
.LP
|
||
|
.nf
|
||
|
struct iovec {
|
||
|
void *iov_base;
|
||
|
size_t iov_len;
|
||
|
};
|
||
|
.fi
|
||
|
.LP
|
||
|
Each
|
||
|
.I iovec
|
||
|
entry specifies the base address and length of an area
|
||
|
in memory where data should be placed.
|
||
|
.BR readv
|
||
|
will always fill an area completely before proceeding
|
||
|
to the next.
|
||
|
.LP
|
||
|
On objects capable of seeking, the
|
||
|
.BR read
|
||
|
starts at a position
|
||
|
given by the pointer associated with
|
||
|
.I d
|
||
|
(see
|
||
|
.BR lseek (2)).
|
||
|
Upon return from
|
||
|
.BR read ,
|
||
|
the pointer is incremented by the number of bytes actually read.
|
||
|
.LP
|
||
|
Objects that are not capable of seeking always read from the current
|
||
|
position. The value of the pointer associated with such an
|
||
|
object is undefined.
|
||
|
.LP
|
||
|
Upon successful completion,
|
||
|
.BR read
|
||
|
and
|
||
|
.BR readv
|
||
|
return the number of bytes actually read and placed in the buffer.
|
||
|
The system guarantees to read the number of bytes requested if
|
||
|
the descriptor references a normal file that has that many bytes left
|
||
|
before the end-of-file, but in no other case.
|
||
|
.LP
|
||
|
If the file was opened with the GNO-specific flag
|
||
|
.BR O_TRANS ,
|
||
|
then newline translation will occur; any carridge return character (0x0d)
|
||
|
read from descriptor
|
||
|
.I d
|
||
|
will be converted to a line feed (0x0a).
|
||
|
.SH RETURN VALUES
|
||
|
If successful, the
|
||
|
number of bytes actually read is returned. Upon reading end-of-file,
|
||
|
zero is returned.
|
||
|
Otherwise, a -1 is returned and the global variable
|
||
|
.IR errno
|
||
|
is set to indicate the error.
|
||
|
.SH ERRORS
|
||
|
.BR read
|
||
|
and
|
||
|
.BR readv
|
||
|
will succeed unless:
|
||
|
.RS
|
||
|
.IP \fBEBADF\fR
|
||
|
.I D
|
||
|
is not a valid file or socket descriptor open for reading.
|
||
|
.IP \fBEFAULT\fR
|
||
|
.I Buf
|
||
|
points outside the allocated address space.
|
||
|
.IP \fBEIO\fR
|
||
|
An I/O error occurred while reading from the file system.
|
||
|
.IP \fBEINTR\fR
|
||
|
A read from a slow device was interrupted before
|
||
|
any data arrived by the delivery of a signal.
|
||
|
.IP \fBEINVAL\fR
|
||
|
The pointer associated with
|
||
|
.I d
|
||
|
was negative.
|
||
|
.IP \fBEAGAIN\fR
|
||
|
The file was marked for non-blocking I/O,
|
||
|
and no data were ready to be read.
|
||
|
.RE
|
||
|
.LP
|
||
|
In addition,
|
||
|
.BR readv
|
||
|
may return one of the following errors:
|
||
|
.RS
|
||
|
.IP \fBEINVAL\fR
|
||
|
.I Iovcnt
|
||
|
was less than or equal to 0, or greater than 16.
|
||
|
.IP \fBEINVAL\fR
|
||
|
One of the
|
||
|
.I iov_len
|
||
|
values in the
|
||
|
.I iov
|
||
|
array was negative.
|
||
|
.IP \fBEINVAL\fR
|
||
|
The sum of the
|
||
|
.I iov_len
|
||
|
values in the
|
||
|
.I iov
|
||
|
array overflowed a 32-bit integer.
|
||
|
.RE
|
||
|
.SH SEE ALSO
|
||
|
.BR dup (2),
|
||
|
.BR fcntl (2),
|
||
|
.BR open (2),
|
||
|
.BR pipe (2),
|
||
|
.BR select (2),
|
||
|
.BR socket (2),
|
||
|
.BR socketpair (2)
|
||
|
.SH STANDARDS
|
||
|
.BR Read
|
||
|
is expected to conform to IEEE Std 1003.1-1988 (POSIX).
|
||
|
.SH HISTORY
|
||
|
The
|
||
|
.BR readv
|
||
|
function call
|
||
|
appeared in 4.2BSD.
|
||
|
A
|
||
|
.BR read
|
||
|
function call
|
||
|
appeared in
|
||
|
Version 6 AT&T UNIX.
|