os161 / man / syscall / read.html
read.html
Raw
<!--
Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009, 2013
	The President and Fellows of Harvard College.

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. 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 UNIVERSITY 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 UNIVERSITY 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.
-->
<html>
<head>
<title>read</title>
<body bgcolor=#ffffff>
<h2 align=center>read</h2>
<h4 align=center>OS/161 Reference Manual</h4>

<h3>Name</h3>
<p>
read - read data from file
</p>

<h3>Library</h3>
<p>
Standard C Library (libc, -lc)
</p>

<h3>Synopsis</h3>
<p>
<tt>#include &lt;unistd.h&gt;</tt><br>
<br>
<tt>ssize_t</tt><br>
<tt>read(int </tt><em>fd</em><tt>, void *</tt><em>buf</em><tt>,
size_t </tt><em>buflen</em><tt>);</tt>
</p>

<h3>Description</h3>
<p>
<tt>read</tt> reads up to <em>buflen</em> bytes from the file
specified by <em>fd</em>, at the location in the file specified by the
current seek position of the file, and stores them in the space
pointed to by <em>buf</em>. The file must be open for reading.
</p>

<p>
The current seek position of the file is advanced by the number of
bytes read.
</p>

<p>
Each read (or <A HREF=write.html>write</A>) operation is atomic
relative to other I/O to the same file.
Note that the kernel is not obliged to (and generally cannot) make the
read atomic with respect to other threads in the same process
accessing the I/O buffer during the read.
</p>

<h3>Return Values</h3>
<p>
The count of bytes read is returned. This count should be
positive. A return value of 0 should be construed as signifying
end-of-file. On error, <tt>read</tt> returns -1 and sets
<A HREF=errno.html>errno</A> to a suitable error code for the error
condition encountered.
</p>

<p>
Note that in some cases, particularly on devices, fewer than
<em>buflen</em> (but greater than zero) bytes may be returned. This
depends on circumstances and does not necessarily signify
end-of-file.
</p>

<h3>Errors</h3>
<p>
The following error codes should be returned under the conditions
given. Other error codes may be returned for other cases not
mentioned here.

<table width=90%>
<tr><td width=5% rowspan=3>&nbsp;</td>
    <td width=10% valign=top>EBADF</td>
			<td><em>fd</em> is not a valid file descriptor, or was
			not opened for reading.</td></tr>
<tr><td valign=top>EFAULT</td>
			<td>Part or all of the address space pointed to by
			<em>buf</em> is invalid.</td></tr>
<tr><td valign=top>EIO</td>
			<td>A hardware I/O error occurred reading the
			data.</td></tr>
</table>
</p>

</body>
</html>