xref: /csrg-svn/lib/libc/sys/read.2 (revision 66257)
161183Sbostic.\" Copyright (c) 1980, 1991, 1993
261183Sbostic.\"	The Regents of the University of California.  All rights reserved.
320047Smckusick.\"
447208Scael.\" %sccs.include.redist.man%
520047Smckusick.\"
6*66257Sbostic.\"     @(#)read.2	8.4 (Berkeley) 02/26/94
747208Scael.\"
847208Scael.Dd
947208Scael.Dt READ 2
1047208Scael.Os BSD 4
1147208Scael.Sh NAME
1247208Scael.Nm read ,
1347208Scael.Nm readv
1447208Scael.Nd read input
1547208Scael.Sh SYNOPSIS
1647208Scael.Fd #include <sys/types.h>
1747208Scael.Fd #include <sys/uio.h>
1866180Sbostic.Fd #include <unistd.h>
1947208Scael.Ft ssize_t
2053283Sbostic.Fn read "int d" "void *buf" "size_t nbytes"
2166202Sbostic.Ft ssize_t
22*66257Sbostic.Fn readv "int d" "const struct iovec *iov" "int iovcnt"
2347208Scael.Sh DESCRIPTION
2447208Scael.Fn Read
2520048Smckusickattempts to read
2647208Scael.Fa nbytes
2720048Smckusickof data from the object referenced by the descriptor
2847208Scael.Fa d
2920048Smckusickinto the buffer pointed to by
3047208Scael.Fa buf .
3147208Scael.Fn Readv
3220048Smckusickperforms the same action, but scatters the input data
3320048Smckusickinto the
3447208Scael.Fa iovcnt
3520048Smckusickbuffers specified by the members of the
3647208Scael.Fa iov
3720048Smckusickarray: iov[0], iov[1], ..., iov[iovcnt\|\-\|1].
3847208Scael.Pp
3920048SmckusickFor
4047208Scael.Fn readv ,
4120048Smckusickthe
4247208Scael.Fa iovec
4366180Sbosticstructure is defined as:
4466180Sbostic.Pp
4547208Scael.Bd -literal -offset indent -compact
4620048Smckusickstruct iovec {
4753283Sbostic	void *iov_base;
4866180Sbostic	size_t iov_len;
4920048Smckusick};
5047208Scael.Ed
5147208Scael.Pp
5220048SmckusickEach
5347208Scael.Fa iovec
5420048Smckusickentry specifies the base address and length of an area
5520048Smckusickin memory where data should be placed.
5647208Scael.Fn Readv
5720048Smckusickwill always fill an area completely before proceeding
5820048Smckusickto the next.
5947208Scael.Pp
6020048SmckusickOn objects capable of seeking, the
6147208Scael.Fn read
6220048Smckusickstarts at a position
6320048Smckusickgiven by the pointer associated with
6447208Scael.Fa d
6528638Skjd(see
6647208Scael.Xr lseek 2 ) .
6720048SmckusickUpon return from
6847208Scael.Fn read ,
6920048Smckusickthe pointer is incremented by the number of bytes actually read.
7047208Scael.Pp
7120048SmckusickObjects that are not capable of seeking always read from the current
7226400Slepreauposition.  The value of the pointer associated with such an
7320048Smckusickobject is undefined.
7447208Scael.Pp
7520048SmckusickUpon successful completion,
7647208Scael.Fn read
7720048Smckusickand
7847208Scael.Fn readv
7920048Smckusickreturn the number of bytes actually read and placed in the buffer.
8020048SmckusickThe system guarantees to read the number of bytes requested if
8128125Skarelsthe descriptor references a normal file that has that many bytes left
8228125Skarelsbefore the end-of-file, but in no other case.
8347208Scael.Pp
8447208Scael.Sh RETURN VALUES
8520048SmckusickIf successful, the
8647208Scaelnumber of bytes actually read is returned. Upon reading end-of-file,
8747208Scaelzero is returned.
8847208ScaelOtherwise, a -1 is returned and the global variable
8947208Scael.Va errno
9020048Smckusickis set to indicate the error.
9147208Scael.Sh ERRORS
9247208Scael.Fn Read
9320048Smckusickand
9447208Scael.Fn readv
9547208Scaelwill succeed unless:
9647208Scael.Bl -tag -width Er
9747208Scael.It Bq Er EBADF
9847208Scael.Fa D
9947208Scaelis not a valid file or socket descriptor open for reading.
10047208Scael.It Bq Er EFAULT
10147208Scael.Fa Buf
10247208Scaelpoints outside the allocated address space.
10347208Scael.It Bq Er EIO
10424439SmckusickAn I/O error occurred while reading from the file system.
10547208Scael.It Bq Er EINTR
10620048SmckusickA read from a slow device was interrupted before
10720048Smckusickany data arrived by the delivery of a signal.
10847208Scael.It Bq Er EINVAL
10926400SlepreauThe pointer associated with
11047208Scael.Fa d
11126400Slepreauwas negative.
11253310Sbostic.It Bq Er EAGAIN
11328125SkarelsThe file was marked for non-blocking I/O,
11428125Skarelsand no data were ready to be read.
11547208Scael.El
11647208Scael.Pp
11720048SmckusickIn addition,
11847208Scael.Fn readv
11920048Smckusickmay return one of the following errors:
12047208Scael.Bl -tag -width Er
12147208Scael.It Bq Er EINVAL
12247208Scael.Fa Iovcnt
12320048Smckusickwas less than or equal to 0, or greater than 16.
12447208Scael.It Bq Er EINVAL
12520048SmckusickOne of the
12647208Scael.Fa iov_len
12720048Smckusickvalues in the
12847208Scael.Fa iov
12920048Smckusickarray was negative.
13047208Scael.It Bq Er EINVAL
13120048SmckusickThe sum of the
13247208Scael.Fa iov_len
13320048Smckusickvalues in the
13447208Scael.Fa iov
13520048Smckusickarray overflowed a 32-bit integer.
13647208Scael.It Bq Er EFAULT
13747208ScaelPart of the
13847208Scael.Fa iov
13947208Scaelpoints outside the process's allocated address space.
14047208Scael.El
14147208Scael.Sh SEE ALSO
14247208Scael.Xr dup 2 ,
14347208Scael.Xr fcntl 2 ,
14447208Scael.Xr open 2 ,
14547208Scael.Xr pipe 2 ,
14647208Scael.Xr select 2 ,
14747208Scael.Xr socket 2 ,
14847208Scael.Xr socketpair 2
14947208Scael.Sh STANDARDS
15047208Scael.Fn Read
15147208Scaelis expected to conform to IEEE Std 1003.1-1988
15247208Scael.Pq Dq Tn POSIX .
15347208Scael.Sh HISTORY
15447208ScaelThe
15547208Scael.Fn readv
15647208Scaelfunction call
15747208Scaelappeared in
15847208Scael.Bx 4.2 .
15947208ScaelA
16047208Scael.Nm read
16147208Scaelfunction call
16247208Scaelappeared in
16347208ScaelVersion 6 AT&T UNIX.
164