Files
oldlinux-files/Minix/2.0.0/wwwman/man2/read.2.html
2024-02-19 00:21:39 -05:00

124 lines
2.8 KiB
HTML

<HTML>
<HEAD>
<TITLE>read(2)</TITLE>
</HEAD>
<BODY>
<H1>read(2)</H1>
<HR>
<PRE>
</PRE>
<H2>NAME</H2><PRE>
read - read input
</PRE>
<H2>SYNOPSIS</H2><PRE>
<STRONG>#include</STRONG> <STRONG>&lt;sys/types.h&gt;</STRONG>
<STRONG>#include</STRONG> <STRONG>&lt;unistd.h&gt;</STRONG>
<STRONG>ssize_t</STRONG> <STRONG>read(int</STRONG> <EM>d</EM><STRONG>,</STRONG> <STRONG>void</STRONG> <STRONG>*</STRONG><EM>buf</EM><STRONG>,</STRONG> <STRONG>size_t</STRONG> <EM>nbytes</EM><STRONG>)</STRONG>
</PRE>
<H2>DESCRIPTION</H2><PRE>
<STRONG>Read</STRONG> attempts to read <EM>nbytes</EM> of data from the object referenced by the
descriptor <EM>d</EM> into the buffer pointed to by <EM>buf</EM>.
On objects capable of seeking, the <STRONG>read</STRONG> starts at a position given by the
pointer associated with <EM>d</EM> (see <STRONG><A HREF="../man2/lseek.2.html">lseek(2)</A></STRONG>). Upon return from <STRONG>read</STRONG>, the
pointer is incremented by the number of bytes actually read.
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.
Upon successful completion, <STRONG>read</STRONG> 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.
If the returned value is 0, then end-of-file has been reached.
</PRE>
<H2>RETURN VALUE</H2><PRE>
If successful, the number of bytes actually read is returned. Otherwise,
a -1 is returned and the global variable <STRONG>errno</STRONG> is set to indicate the
error.
</PRE>
<H2>ERRORS</H2><PRE>
<STRONG>Read</STRONG> will fail if one or more of the following are true:
[EBADF] <EM>D</EM> is not a valid descriptor open for reading.
[EFAULT] <EM>Buf</EM> points outside the allocated address space.
[EIO] An I/O error occurred while reading from the file system.
[EINTR] A read from a slow device was interrupted before any data
arrived by the delivery of a signal.
[EAGAIN] The file was marked for non-blocking I/O, and no data were
ready to be read.
</PRE>
<H2>SEE ALSO</H2><PRE>
<STRONG><A HREF="../man2/dup.2.html">dup(2)</A></STRONG>, <STRONG><A HREF="../man2/fcntl.2.html">fcntl(2)</A></STRONG>, <STRONG><A HREF="../man2/open.2.html">open(2)</A></STRONG>, <STRONG><A HREF="../man2/pipe.2.html">pipe(2)</A></STRONG>, <STRONG><A HREF="../man2/write.2.html">write(2)</A></STRONG>.
</PRE>
</BODY>
</HTML>