ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/read.htm

989 lines
26 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
<title>read()--Read from Descriptor</title>
<!-- Begin Header Records ========================================== -->
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<!-- file cleaned -->
<!-- Unix2 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
<!-- Change History: -->
<!-- 010307 JTROUS Change to xref pread, pread64, pwrite, -->
<!-- pwrite64 for V5R2, DCR 98686 -->
<!-- 010703 JTROUS Add ERESTART, EINTR, V5R2, DCR 98686, add dev/zero-->
<!-- 011022 JTROUS Changes from API Review 1, V5R2 -->
<!-- 020618 EMIG: updated for NFS threadsafety, V5R3 -->
<!-- 020624 RTHEIS: Add fclear() and fclear64(), V5R3 -->
<!-- 0206?? JET This file has undergone html cleanup -->
<!-- 020718 MFENLON: updated for QFileSvr.400 threadsafety, V5R3 -->
<!-- 050407 JTROUS: fix enums, no change flag, V5R4 -->
<!-- End Header Records -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<a name="Top_Of_Page"></a>
<!-- Java sync-link -->
<script language="Javascript" src="../rzahg/synch.js" type="text/javascript">
</script>
<h2>read()--Read from Descriptor</h2>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;unistd.h&gt;
ssize_t read(int <em>file_descriptor</em>,
void <em>*buf</em>, size_t <em>nbyte</em>);
</pre>
&nbsp;&nbsp;Service Program Name: QP0LLIB1<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Conditional; see <a href="#USAGE_NOTES">Usage
Notes</a>.<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>From the file or socket indicated by <em>file_descriptor</em>, the <strong>
read()</strong> function reads <em>nbyte</em> bytes of input into the memory
area indicated by <em>buf</em>. If <em>nbyte</em> is zero, <strong>
read()</strong> returns a value of zero without attempting any other
action.</p>
<p>If <em>file_descriptor</em> refers to a "regular file" (a stream file that
can support positioning the file offset) or any other type of file on which the
job can do an <strong>lseek()</strong> operation, <strong>read()</strong>
begins reading at the file offset associated with <em>file_descriptor</em>. A
successful <strong>read()</strong> changes the file offset by the number of
bytes read.</p>
<p>If <strong>read()</strong> is successful and <em>nbyte</em> is greater than
zero, the access time for the file is updated.</p>
<p><strong>read()</strong> is not supported for directories.</p>
<p>If <em>file_descriptor</em> refers to a descriptor obtained using the
<strong>open()</strong> function with O_TEXTDATA specified, the data is read
from the file assuming it is in textual form. The maximum number of bytes on a
single read that can be supported for text data is 2,147,483,408 (2GB - 240)
bytes. The data is converted from the code page of the file to the code page of
the application, job, or system as follows:</p>
<ul>
<li>When reading from a true stream file, any line-formatting characters (such
as carriage return, tab, and end-of-file) are just converted from one code page
to another.<br>
</li>
<li>When reading from record files that are being used as stream files,
end-of-line characters are added to the end of the data in each record.</li>
</ul>
<p>There are some important considerations when the file is open for text
conversion and the CCSIDs involved are not strictly single-byte:</p>
<ul>
<li>The <strong>read()</strong> will return the exact number of bytes
requested. For some CCSIDs, this may mean that partial characters are returned
at the end of the user buffer. In this case, the remainder of the character has
been read from the file and internally buffered. The next consecutive read()
will begin with the remainder of the partial character. However, if an <strong>
lseek()</strong> is performed, the buffered data will be discarded. See <a
href="lseek.htm">lseek()--Set File Read/Write Offset</a> for more
information.<br>
</li>
<li>Because of the above consideration and because of the possible expansion or
contraction of converted data, applications using the O_CCSID flag should avoid
assumptions about data size and the current file offset. For example, a file
might have a physical size of 100 bytes, but after an application has read 100
bytes from the file, the current file offset may be 50. In order to read the
whole file, the application might have to read 200 bytes or more, depending on
the CCSIDs involved.</li>
</ul>
<p>If O_TEXTDATA was not specified on the <strong>open()</strong>, the data is
read from the file without conversion. The application is responsible for
handling the data.</p>
<p>In the QSYS.LIB and independent ASP QSYS.LIB file systems, most end-of-file
characters are symbolic; that is, they are stored outside the member. When
reading:</p>
<ul>
<li>If O_TEXTDATA is specified, both symbolic and nonsymbolic end-of-file
characters can be seen.<br>
</li>
<li>If O_TEXTDATA is not specified (binary mode), only nonsymbolic end-of-file
characters can be seen.</li>
</ul>
<p>See the <em>Usage Notes</em> for <a href="write.htm">write()--Write to
Descriptor</a>.</p>
<p>When <em>file_descriptor</em> refers to a socket, the <strong>
read()</strong> function reads from the socket identified by the socket
descriptor.</p>
<p>When attempting to read from an empty pipe or FIFO:</p>
<ul>
<li>If no job has the pipe or FIFO open for writing, <strong>read()</strong>
return 0 to indicate end-of-file.<br>
</li>
<li>If some job has the pipe or FIFO open for writing and O_NONBLOCK was
specified, <strong>read()</strong> will fail and <em>errno</em> will be set
to [EAGAIN].<br>
</li>
<li>If some job has the pipe or FIFO open for writing and O_NONBLOCK was not
specified, <strong>read()</strong> will block the calling thread until some
data is written or until the pipe or FIFO is closed by all jobs that had the
pipe or FIFO open for writing.</li>
</ul>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong>file_descriptor</strong></dt>
<dd>(Input) The descriptor to be read.<br>
</dd>
<dt><strong>buf</strong></dt>
<dd>(Output) A pointer to a buffer in which the bytes read are placed.<br>
</dd>
<dt><strong>nbyte</strong></dt>
<dd>(Input) The number of bytes to be read.</dd>
</dl>
<br>
<h3>Authorities</h3>
<p>No authorization is required.</p>
<br>
<h3>Return Value</h3>
<dl>
<dt><em>value</em></dt>
<dd><strong>read()</strong> was successful. The value returned is the number of
bytes actually read and placed in <em>buf</em>. This number is less than or
equal to <em>nbyte</em>. It is less than <em>nbyte</em> only if <strong>
read()</strong> reached the end of the file before reading the requested number
of bytes. If <strong>read()</strong> is reading a regular file and encounters a
part of the file that has not been written (but before the end of the file),
<strong>read()</strong> places bytes containing zeros into <em>buf</em> in
place of the unwritten bytes.</dd>
<dt><em>-1</em></dt>
<dd><strong>read()</strong> was not successful. The <em>errno</em> global
variable is set to indicate the error. If the value of <em>nbyte</em> is
greater than SSIZE_MAX, <strong>read()</strong> sets <em>errno</em> to
[EINVAL].</dd>
</dl>
<br>
<h3>Error Conditions</h3>
<p>If <strong>read()</strong> is not successful, <em>errno</em> usually
indicates one of the following errors. Under some conditions, <em>errno</em>
could indicate an error other than those listed here.</p>
<table cellpadding="5">
<!-- cols="25 75" -->
<tr>
<th align="left" valign="bottom">Error condition</th>
<th align="left" valign="bottom">Additional information</th>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EACCES">EACCES</a>]</em></td>
<td align="left" valign="top">
<p>If you are accessing a remote file through the Network File System, update
operations to file permissions at the server are not reflected at the client
until updates to data that is stored locally by the Network File System take
place. (Several options on the Add Mounted File System (ADDMFS) command
determine the time between refresh operations of local data.) Access to a
remote file may also fail due to different mappings of user IDs (UID) or group
IDs (GID) on the local and remote systems.</p>
<p>This may occur if <em>file_descriptor</em> refers to a socket and the socket
is using a connection-oriented transport service, and a <em>connect()</em> was
previously completed. The thread, however, does not have the appropriate
privileges to the objects that were needed to establish a connection. For
example, the <em>connect()</em> required the use of an APPC device that the
thread was not authorized to.</p>
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EAGAIN">EAGAIN</a>]</em></td>
<td align="left" valign="top">
<p>If <em>file_descriptor</em> refers to a pipe or FIFO that has its O_NONBLOCK
flag set, this error occurs if the <strong>read()</strong> would have blocked
the calling thread.</p>
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EBADF">EBADF</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EBADFID">EBADFID</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EBUSY">EBUSY</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EDAMAGE">EDAMAGE</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EFAULT">EFAULT</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EINTR">EINTR</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EINVAL">EINVAL</a>]</em></td>
<td align="left" valign="top">
<p>This may occur if <em>file_descriptor</em> refers to a socket that is using
a connectionless transport service, is not a socket of type <samp>
SOCK_RAW</samp>, and is not bound to an address.</p>
<p>The file resides in a file system that does not support large files, and the
starting offset of the file exceeds 2GB minus 2 bytes.</p>
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EIO">EIO</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ENOMEM">ENOMEM</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ENOTAVAIL">ENOTAVAIL</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ENOTSAFE">ENOTSAFE</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ENXIO">ENXIO</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EOVERFLOW">EOVERFLOW</a>]</em></td>
<td align="left" valign="top">
<p>The file is a regular file, <em>nbyte</em> is greater than 0, the starting
offset is before the end-of-file, and the starting offset is greater than or
equal to 2GB minus 2 bytes.</p>
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ERESTART">ERESTART</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ESTALE">ESTALE</a>]</em></td>
<td align="left" valign="top">
<p>If you are accessing a remote file through the Network File System, the file
may have been deleted at the server.</p>
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EUNKNOWN">EUNKNOWN</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
</table>
<p>When the descriptor refers to a socket, <em>errno</em> could indicate one of
the following errors:</p>
<table cellpadding="5">
<!-- cols="25 75" -->
<tr>
<th align="left" valign="bottom">Error condition</th>
<th align="left" valign="bottom">Additional information</th>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ECONNABORTED">ECONNABORTED</a>]</em></td>
<td>
<p>This error code indicates that the transport provider ended the connection
abnormally because of one of the following:</p>
<ul>
<li>The retransmission limit has been reached for data that was being sent on
the socket.</li>
<li>A protocol error was detected.<br></li>
</ul>
</td></tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ECONNREFUSED">ECONNREFUSED</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ECONNRESET">ECONNRESET</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EINTR">EINTR</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ENOTCONN">ENOTCONN</a>]</em></td>
<td align="left" valign="top">
<p>This error code is returned only on sockets that use a connection-oriented
transport service.</p>
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ETIMEDOUT">ETIMEDOUT</a>]</em></td>
<td align="left" valign="top">
<p>A non-blocking <strong>connect()</strong> was previously completed that
resulted in the connection timing out. No connection is established. This error
code is returned only on sockets that use a connection-oriented transport
service.</p>
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EUNATCH">EUNATCH</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EWOULDBLOCK">EWOULDBLOCK</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
</table>
<p>If interaction with a file server is required to access the object, <em>
errno</em> could indicate one of the following errors:</p>
<table cellpadding="5">
<!-- cols="25 75" -->
<tr>
<th align="left" valign="bottom">Error condition</th>
<th align="left" valign="bottom">Additional information</th>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EADDRNOTAVAIL">EADDRNOTAVAIL</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ECONNABORTED">ECONNABORTED</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ECONNREFUSED">ECONNREFUSED</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ECONNRESET">ECONNRESET</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EHOSTDOWN">EHOSTDOWN</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EHOSTUNREACH">EHOSTUNREACH</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ENETDOWN">ENETDOWN</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ENETRESET">ENETRESET</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ENETUNREACH">ENETUNREACH</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ESTALE">ESTALE</a>]</em></td>
<td align="left" valign="top">
<p>If you are accessing a remote file through the Network File System, the file
may have been deleted at the server.</p>
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ETIMEDOUT">ETIMEDOUT</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EUNATCH">EUNATCH</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
</table>
<br>
<br>
<h3>Error Messages</h3>
<p>The following messages may be sent from this function:</p>
<table width="100%" cellpadding="5">
<tr>
<th align="left" valign="top">Message ID</th>
<th align="left" valign="top">Error Message Text</th>
</tr>
<tr>
<td align="left" valign="top">CPE3418 E</td>
<td align="left" valign="top">Possible APAR condition or hardware failure.</td>
</tr>
<tr>
<td align="left" valign="top">CPF3CF2 E</td>
<td align="left" valign="top">Error(s) occurred during running of &amp;1
API.</td>
</tr>
<tr>
<td align="left" valign="top">CPF9872 E</td>
<td align="left" valign="top">Program or service program &amp;1 in library
&amp;2 ended. Reason code &amp;3.</td>
</tr>
<tr>
<td align="left" valign="top">CPFA081 E</td>
<td align="left" valign="top">Unable to set return value or error code.</td>
</tr>
<tr>
<td align="left" valign="top">CPFA0D4 E</td>
<td align="left" valign="top">File system error occurred. Error number
&amp;1.</td>
</tr>
</table>
<br>
<br>
<h3><a name="usage_notes">Usage Notes</a></h3>
<ol>
<li>This function will fail with error code [ENOTSAFE] when all the following
conditions are true:
<ul>
<li>Where multiple threads exist in the job.<br>
</li>
<li>The object on which this function is operating resides in a file system
that is not threadsafe. Only the following file systems are threadsafe for this
function:<br>
<br>
<ul>
<li>"Root" (/)</li>
<li>QOpenSys</li>
<li>User-defined</li>
<li>QNTC</li>
<li>QSYS.LIB</li>
<li>Independent ASP QSYS.LIB</li>
<li>QOPT</li>
<li>Network File System</li>
<li>QFileSvr.400</li>
</ul>
</li>
</ul>
<br>
</li>
<li>QSYS.LIB and Independent ASP QSYS.LIB File System Differences
<p>This function will fail with error code [ENOTSAFE] if the object on which
this function is operation is a save file and multiple threads exist in the
job.</p>
<p>This function will fail with error code [EIO] if the file specified is a
save file and the file does not contain complete save file data.</p>
<p>The file access time for a database member is updated using the normal rules
that apply to database files. At most, the access time is updated once per
day.</p>
<p>If you previously used the integrated file system interface to manipulate a
member that contains an end-of-file character, you should avoid using other
interfaces (such as the Source Entry Utility or database reads and writes) to
manipulate the member. If you use other interfaces after using the integrated
file system interface, the end-of-file information will be lost.</p>
<br>
</li>
<li>QOPT File System Differences
<p>The file access time is not updated on a <strong>read()</strong>
operation.</p>
<p>When reading from files on volumes formatted in Universal Disk Format (UDF),
byte locks on the range being read are ignored.</p>
<br>
</li>
<li>Network File System Differences
<p>Local access to remote files through the Network File System may produce
unexpected results due to conditions at the server. Once a file is open,
subsequent requests to perform operations on the file can fail because file
attributes are checked at the server on each request. If permissions on the
file are made more restrictive at the server or the file is unlinked or made
unavailable by the server for another client, your operation on an open file
descriptor will fail when the local Network File System receives these updates.
The local Network File System also impacts operations that retrieve file
attributes. Recent changes at the server may not be available at your client
yet, and old values may be returned from operations. (Several options on the
Add Mounted File System (ADDMFS) command determine the time between refresh
operations of local data.)</p>
<p>Reading and writing to files with the Network File System relies on
byte-range locking to guarantee data integrity. To prevent data inconsistency,
use the <strong>fcntl()</strong> API to get and release these locks.</p>
<br>
</li>
<li>QFileSvr.400 File System Differences
<p>The largest buffer size allowed is 16 megabytes. If a larger buffer is
passed, the error EINVAL will be received.</p>
<br>
</li>
<li>For sockets that use a connection-oriented transport service (for example,
sockets with a type of <samp>SOCK_STREAM</samp>), a return value of zero
indicates one of the following:
<ul>
<li>The partner program has issued a <strong>close()</strong> for the
socket.<br>
</li>
<li>The partner program has issued a <strong>shutdown()</strong> to disable
writing to the socket.<br>
</li>
<li>The connection is broken and the error was returned on a previously issued
socket function.<br>
</li>
<li>A <strong>shutdown()</strong> to disable reading was previously done on the
socket.</li>
</ul>
<br>
</li>
<li>The following applies to sockets that use a connectionless transport
service (for example, a socket with a type of <samp>SOCK_DGRAM</samp>).
<ul>
<li>If a <strong>connect()</strong> has been issued previously, then data can
be received only from the address specified in the previous <strong>
connect()</strong>.<br>
</li>
<li>The address from which data is received is discarded, since the <strong>
read()</strong> has no address parameter.<br>
</li>
<li>The entire message must be read in a single read operation. If the size of
the message is too large to fit in the user supplied buffer, the remaining
bytes of the message are discarded.<br>
</li>
<li>A returned value of zero indicates one of the following:
<ul>
<li>The partner program has sent a NULL message (a datagram with no user
data).<br>
</li>
<li>A <strong>shutdown()</strong> to disable reading was previously done on the
socket.<br>
</li>
<li>The buffer length specified was zero.</li>
</ul>
</li>
</ul>
<br>
</li>
<li>For file systems that do not support large files, <strong>read()</strong>
will return [EINVAL] if the starting offset exceeds 2GB minus 2 bytes,
regardless of how the file was opened. For the file systems that do support
large files, <strong>read()</strong> will return [EOVERFLOW] if the starting
offset exceeds 2GB minus 2 bytes and the file was not opened for large file
access.<br>
<br>
</li>
<li>Using this function successfully on the /dev/null or /dev/zero character
special file results in a return value of zero. In addition, the access time
for the file is updated.</li>
</ol>
<br>
<h3>Related Information</h3>
<ul>
<li>The &lt;<strong>limits.h</strong>&gt; file (see <a href="unix13.htm">Header
Files for UNIX-Type Functions</a>)
</li>
<li>The &lt;<strong>unistd.h</strong>&gt; file (see <a href="unix13.htm">Header
Files for UNIX-Type Functions</a>)
</li>
<li><a href="creat.htm">creat()</a>--Create or Rewrite File
</li>
<li><a href="dup.htm">dup()</a>--Duplicate Open File Descriptor
</li>
<li><a href="dup2.htm">dup2()</a>--Duplicate Open File Descriptor to Another
Descriptor
</li>
<li><a href="fclear.htm">fclear()</a>--Write (Binary Zeros) to Descriptor
</li>
<li><a href="fclear64.htm">fclear64()</a>--Write (Binary Zeros) to Descriptor
(Large File Enabled)</li>
<li><a href="fcntl.htm">fcntl()</a>--Perform File Control Command
</li>
<li><a href="ioctl.htm">ioctl()</a>--Perform I/O Control Request
</li>
<li><a href="lseek.htm">lseek()</a>--Set File Read/Write Offset
</li>
<li><a href="open.htm">open()</a>--Open File
</li>
<li><a href="pread.htm">pread()</a>--Read from Descriptor with Offset
</li>
<li><a href="pread64.htm">pread64()</a>--Read from Descriptor with Offset
(large file enabled)
</li>
<li><a href="pwrite.htm">pwrite()</a>--Write to Descriptor with Offset
</li>
<li><a href="pwrite64.htm">pwrite64()</a>--Write to Descriptor with Offset
(large file enabled)
</li>
<li><a href="readv.htm">readv()</a>--Read from Descriptor Using Multiple
Buffers
</li>
<li><a href="recv.htm">recv()</a>--Receive Data
</li>
<li><a href="recvfr.htm">recvfrom()</a>--Receive Data
</li>
<li><a href="recvms.htm">recvmsg()</a>--Receive Data or Descriptors or Both
</li>
<li><a href="write.htm">write()</a>--Write to Descriptor
</li>
<li><a href="writev.htm">writev()</a>--Write to Descriptor Using Multiple
Buffers</li>
</ul>
<br>
<h3>Example</h3>
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
for information pertaining to code examples.</p>
<p>The following example opens a file and reads input:</p>
<pre>
#include &lt;stdio.h&gt;
#include &lt;unistd.h&gt;
#include &lt;fcntl.h&gt;
main() {
int ret, file_descriptor, rc;
char buf[]="Test text";
if ((file_descriptor = creat("test.output", S_IWUSR))!= 0)
perror("creat() error");
else {
if (-1==(rc=write(file_descriptor, buf, sizof(buf)-1)))
perror("write() error");
if (close(file_descriptor)!= 0)
perror("close() error");
}
if ((file_descriptor = open("test.output", O_RDONLY)) &lt; 0)
perror("open() error");
else {
ret = read(file_descriptor, buf, sizeof(buf)-1));
buf[ret] = 0x00;
printf("block read: \n&lt;%s&gt;\", buf);
if (close(file_descriptor)!= 0)
perror("close() error");
}
if (unlink("test.output")!= 0)
perror("unlink() error");
}
</pre>
<p><strong>Output:</strong></p>
<pre>
block read:
&lt;Test text&gt;
</pre>
<br>
<hr>
API introduced: V3R1
<hr>
<center>
<table cellpadding="2" cellspacing="2">
<tr align="center">
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
</tr>
</table>
</center>
</body>
</html>