⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 read.2

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 2
字号:
.\" SCCSID: @(#)read.2	2.1	3/10/87.TH read 2.SH Nameread, readv \- read from a file.SH Syntax.nfcc = read(\fId, buf, nbytes\fP)int cc, \fId\fP;char *\fIbuf\fP;int \fInbytes\fP;.PP#include <sys/types.h>#include <sys/uio.h>.PPcc = readv(\fId, iov, iovcnt\fP)int cc, \fId\fP;struct iovec *\fIiov\fP;int \fIiovcnt\fP;.fi.SH Arguments.TP 10.I dFile descriptor..TP 10.I bufCharacter pointer where information is stored..TP 10.I nbytesInteger that tells you how many bytes to read..TP 10.I iovPointer to an.I iovecstructure..TP 10.I iovcntThe number of .I iovecstructures to be processed..SH Description.NXR "read system call".NXR "file" "reading".NXR "socket" "reading".NXR "readv system call".NXR "read system call" "write system call".NXR "read system call" "send system call"The system call.PN readattempts to read.I nbytesof data from the object referenced by the descriptor.I dinto the buffer pointed to by.IR buf .The.PN readvsystem call performs the same action, but scatters the input datainto the .I iovcntbuffers specified by the members of the.I iovecfollowing array: iov[0], iov[1], ..., iov[iovcnt\|\-\|1]..PPFor .PN readv ,the .I iovecstructure is defined as follows:.PP.EXstruct iovec {	caddr_t	iov_base;	int	iov_len;};.EE.PPEach .I iovecentry specifies the base address and length of an areain memory where data should be placed. The.PN readvsystem call fills an area completely before proceedingto the next area..PPOn objects that are capable of seeking, the.PN readstarts at a positiongiven by the pointer associated with.IR d .See .MS lseek 2 for more information.Upon return from.PN read ,the pointer is incremented by the number of bytes actually read..PPObjects that are not capable of seeking always read from the currentposition.  The value of the pointer associated with such an object is undefined..PPWhen attempting to read from an empty pipe (or FIFO):.IP \(bu 5If no process has the pipe open for writing, .PN readreturns zero to indicate end-of-file..IP \(bu 5If some process has the pipe open for writing and O_NDELAY or O_NONBLOCK isset, .PN readreturns a \-1,.I errnois to [EWOULDBLOCK].  If some process has the pipe open for writing and O_NDELAY and O_NONBLOCK are clear, .PN readblocks until data is written or the pipe is closed by all processes that opened the pipe for writing..PPUpon successful completion,.PN readand.PN readvreturn the number of bytes actually read and placed in the buffer.The system reads the number of bytes requested ifthe descriptor references a file which has that many bytes leftbefore the end-of-file; this is not true in any other instance..PPUnless the SV_INTERRUPT bit has been set for a signal, the .PN read system calls are automatically restarted when a process receives asignal while waiting for input. See also .MS sigvec 2 ..SH Return ValuesIf the returned value is 0, thenend-of-file has been reached..PPIf the read is successful, thenumber of bytes actually read is returned.Otherwise, a \-1 is returned and the global variable.I errnois set to indicate the error..SH Diagnostics.NXR "read system call" "diagnostics"The.PN readand.PN readvsystem calls fail if one or more of the following are true:.TP 15[EBADF]The.I dargument is not a valid file or socket descriptor open for reading..TP 15[EFAULT]The\fIbuf\fP points outside the allocated address space..TP 15[EINTR]A read from a slow device was interrupted beforeany data arrived by the delivery of a signal..TP 15[EIO]An I/O error occurred while reading from the file system..TP 15[ESTALE]The file handle given in the argument is invalid. Thefile referred to by that file handle no longer existsor has been revoked..TP 15[EWOULDBLOCK]The O_DELAY or O_NONBLOCK flag is set for the file descriptor and the process would be delayed in the read operation. .PPIn addition, .PN readvmay return one of the following errors:.TP 15[EINVAL]The.I iovcntwas less than or equal to 0, or greater than 16..TP 15[EINVAL]One of the.I iov_lenvalues in the.I iovarray was negative..TP 15[EINVAL]The sum of the.I iov_lenvalues in the.I iovarray overflowed a 32-bit integer..TP 15[EFAULT]Part of the .I iovpoints outside the process's allocated address space..TP[ETIMEDOUT]A connect request or remote file operation failedbecause the connected party did not respond after a periodof time determined by the communications protocol..SH Environment.NXR "read system call" "System V and"SYSTEM_FIVE.PPWhen you use the System V environment, note the following:.IP \(bu 5If your program is compiled in this environment, a .PN readand.PN readvsystem call returns 0 if the file has been set up for non-blockingI/O and the read would block..PP.IP \(bu 5In this environment, the parameter.I nbytesis of type .I int instead of type.I unsigned..PPPOSIX.PPIn the POSIX environment, [EAGAIN] is returned in.I errnoinstead of [EWOULDBLOCK]..SH See Alsodup(2), open(2), pipe(2), sigvec(2), socket(2), socketpair(2)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -