xref: /csrg-svn/lib/libc/sys/read.2 (revision 53310)
147208Scael.\" Copyright (c) 1980, 1991 Regents of the University of California.
247208Scael.\" All rights reserved.
320047Smckusick.\"
447208Scael.\" %sccs.include.redist.man%
520047Smckusick.\"
6*53310Sbostic.\"     @(#)read.2	6.9 (Berkeley) 05/04/92
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 <unistd.h>
1747208Scael.Fd #include <sys/types.h>
1847208Scael.Fd #include <sys/uio.h>
1947208Scael.Ft ssize_t
2053283Sbostic.Fn read "int d" "void *buf" "size_t nbytes"
2147208Scael.Ft int
2247208Scael.Fn readv "int d" "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
4320048Smckusickstructure is defined as
4447208Scael.Bd -literal -offset indent -compact
4520048Smckusickstruct iovec {
4653283Sbostic	void *iov_base;
4753283Sbostic	int iov_len;
4820048Smckusick};
4947208Scael.Ed
5047208Scael.Pp
5120048SmckusickEach
5247208Scael.Fa iovec
5320048Smckusickentry specifies the base address and length of an area
5420048Smckusickin memory where data should be placed.
5547208Scael.Fn Readv
5620048Smckusickwill always fill an area completely before proceeding
5720048Smckusickto the next.
5847208Scael.Pp
5920048SmckusickOn objects capable of seeking, the
6047208Scael.Fn read
6120048Smckusickstarts at a position
6220048Smckusickgiven by the pointer associated with
6347208Scael.Fa d
6428638Skjd(see
6547208Scael.Xr lseek 2 ) .
6620048SmckusickUpon return from
6747208Scael.Fn read ,
6820048Smckusickthe pointer is incremented by the number of bytes actually read.
6947208Scael.Pp
7020048SmckusickObjects that are not capable of seeking always read from the current
7126400Slepreauposition.  The value of the pointer associated with such an
7220048Smckusickobject is undefined.
7347208Scael.Pp
7420048SmckusickUpon successful completion,
7547208Scael.Fn read
7620048Smckusickand
7747208Scael.Fn readv
7820048Smckusickreturn the number of bytes actually read and placed in the buffer.
7920048SmckusickThe system guarantees to read the number of bytes requested if
8028125Skarelsthe descriptor references a normal file that has that many bytes left
8128125Skarelsbefore the end-of-file, but in no other case.
8247208Scael.Pp
8347208Scael.Sh RETURN VALUES
8420048SmckusickIf successful, the
8547208Scaelnumber of bytes actually read is returned. Upon reading end-of-file,
8647208Scaelzero is returned.
8747208ScaelOtherwise, a -1 is returned and the global variable
8847208Scael.Va errno
8920048Smckusickis set to indicate the error.
9047208Scael.Sh ERRORS
9147208Scael.Fn Read
9220048Smckusickand
9347208Scael.Fn readv
9447208Scaelwill succeed unless:
9547208Scael.Bl -tag -width Er
9647208Scael.It Bq Er EBADF
9747208Scael.Fa D
9847208Scaelis not a valid file or socket descriptor open for reading.
9947208Scael.It Bq Er EFAULT
10047208Scael.Fa Buf
10147208Scaelpoints outside the allocated address space.
10247208Scael.It Bq Er EIO
10324439SmckusickAn I/O error occurred while reading from the file system.
10447208Scael.It Bq Er EINTR
10520048SmckusickA read from a slow device was interrupted before
10620048Smckusickany data arrived by the delivery of a signal.
10747208Scael.It Bq Er EINVAL
10826400SlepreauThe pointer associated with
10947208Scael.Fa d
11026400Slepreauwas negative.
111*53310Sbostic.It Bq Er EAGAIN
11228125SkarelsThe file was marked for non-blocking I/O,
11328125Skarelsand no data were ready to be read.
11447208Scael.El
11547208Scael.Pp
11620048SmckusickIn addition,
11747208Scael.Fn readv
11820048Smckusickmay return one of the following errors:
11947208Scael.Bl -tag -width Er
12047208Scael.It Bq Er EINVAL
12147208Scael.Fa Iovcnt
12220048Smckusickwas less than or equal to 0, or greater than 16.
12347208Scael.It Bq Er EINVAL
12420048SmckusickOne of the
12547208Scael.Fa iov_len
12620048Smckusickvalues in the
12747208Scael.Fa iov
12820048Smckusickarray was negative.
12947208Scael.It Bq Er EINVAL
13020048SmckusickThe sum of the
13147208Scael.Fa iov_len
13220048Smckusickvalues in the
13347208Scael.Fa iov
13420048Smckusickarray overflowed a 32-bit integer.
13547208Scael.It Bq Er EFAULT
13647208ScaelPart of the
13747208Scael.Fa iov
13847208Scaelpoints outside the process's allocated address space.
13947208Scael.El
14047208Scael.Sh SEE ALSO
14147208Scael.Xr dup 2 ,
14247208Scael.Xr fcntl 2 ,
14347208Scael.Xr open 2 ,
14447208Scael.Xr pipe 2 ,
14547208Scael.Xr select 2 ,
14647208Scael.Xr socket 2 ,
14747208Scael.Xr socketpair 2
14847208Scael.Sh STANDARDS
14947208Scael.Fn Read
15047208Scaelis expected to conform to IEEE Std 1003.1-1988
15147208Scael.Pq Dq Tn POSIX .
15247208Scael.Sh HISTORY
15347208ScaelThe
15447208Scael.Fn readv
15547208Scaelfunction call
15647208Scaelappeared in
15747208Scael.Bx 4.2 .
15847208ScaelA
15947208Scael.Nm read
16047208Scaelfunction call
16147208Scaelappeared in
16247208ScaelVersion 6 AT&T UNIX.
163