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

836 lines
21 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<!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>fclear()--Write (Binary Zeros) to 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: -->
<!-- 020410 RTHEIS Created V5R3, DCR 99096 -->
<!-- 020618 EMIG Updates for NFS threadsafety, V5R3 -->
<!-- 050325 JTROUS: fix enums, no change flag, V5R4 -->
<!-- 050427 JTROUS: Add QNTC restriction, V5R4 -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<!-- End Header Records --><!-- Edited by Kersten Feb 02 -->
<!-- Java sync-link -->
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
</script>
<a name="Top_Of_Page"></a>
<h2>fclear()--Write (Binary Zeros) to Descriptor</h2>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;unistd.h&gt;
off_t fclear
(int <em>file_descriptor</em>, off_t <em>nbyte</em>);
</pre>
<br>
&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>The <strong>fclear()</strong> function writes <em>nbyte</em> bytes
of binary zeros to the file associated with the <em>file_descriptor</em>.
<em>nbyte</em> should not be greater than INT_MAX (defined in the
&lt;<strong>limits.h</strong>&gt; header file). If it is, [EINVAL] will be returned.
If <em>nbyte</em> is zero,
<strong>fclear()</strong> simply 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), <strong>fclear()</strong>
begins writing binary zeros at the file offset associated with <em>file_descriptor</em>.
A successful
<strong>fclear()</strong> increments the file offset by the number of bytes written.
If the incremented file offset is greater than the previous length of
the file, the length of the file is set to the new file offset.
An unsuccessful <strong>fclear()</strong> will not change the file offset.
If the <em>file_descriptor</em> does not refer to a "regular file", [EINVAL] will be returned.</p>
<p>If O_APPEND (defined in the &lt;<strong>fcntl.h</strong>&gt; header file) is
set for the file, <strong>fclear()</strong> does <b>not</b> set the file offset to the end of
the file before writing the output. Instead, it begins writing binary zeros at the current file
offset associated with the <em>file_descriptor</em>.</p>
<p>If <b>fclear()</b> is called such that <em>nbyte</em>
plus the current file offset will cause the size of the file to exceed
2GB minus 1 bytes when the file is <b>not</b> opened for large file access,
the system allowed maximum file size when the file is opened for large file access,
or the process soft file size limit, [EFBIG] will be returned.</p>
<p>If <strong>fclear()</strong> is successful and <em>nbyte</em> is greater than
zero, the change and modification times for the file are updated.</p>
<p>If <em>file_descriptor</em> refers to a descriptor obtained using the
<strong>open()</strong> function with O_TEXTDATA specified, binary zeros are written
to the file assuming they are in textual form. The data (binary zeros) is
converted from the code page of the application, job, or system, to the code page of the file as
follows:</p>
<ul>
<li>Only simple conversions are performed. That is, if one byte of binary zeros does not
convert to one byte of binary zeros then [ENOTSUP] is returned.
<li>When clearing a physical file in the QSYS.LIB file system the <b>fclear()</b> should not
be performed across a record boundary. If it is, [ETRUNC] will be returned.
</li>
</ul>
<p>Note: The conversion of binary zeros will always result in binary zeros.</p>
<p>There are some important considerations if O_CCSID was specified on the
<strong>open()</strong>.</p>
<ul>
<li>If an <b>fclear()</b> is performed when there are partial characters
buffered internally due to a previous <b>write()</b>, the <b>fclear()</b> will fail
with the [ENOTSUP] error.<br><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.</li>
</ul>
<p>If O_TEXTDATA was not specified on the <strong>open()</strong>, binary zeros
are written to the file without conversion. The application is responsible for
handling the data.</p>
<p><strong>Note:</strong> When the <b>fclear</b> completes successfully, the S_ISUID
(set-user-ID) and S_ISGID (set-group-ID) bits of the file mode will be cleared.
If the <b>fclear()</b> is unsuccessful, the bits are undefined.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong>file_descriptor</strong></dt>
<dd>(Input) The descriptor of the file to be cleared (write binary zeros).
<br><br>
</dd>
<dt><strong>nbyte</strong></dt>
<dd>(Input) Indicates the number of bytes to clear (write binary zeros).
<br><br>
</dd>
</dl>
<br>
<h3>Authorities</h3>
<p>No authorization is required.</p>
<br>
<h3>Return Value</h3>
<table cellpadding="5">
<!-- cols="10 90" -->
<tr>
<td align="left" valign="top"><em>value</em></td>
<td align="left" valign="top"><strong>fclear()</strong> was successful. The
return value is the number of bytes that have been
successfully cleared. This number will be equal to <em>nbyte</em>.
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>-1</em></td>
<td align="left" valign="top"><strong>fclear()</strong> was not successful. The
<strong>fclear()</strong> was not able to clear all of the bytes requested.
No indication is given as to how much data was successfully cleared. In addition,
the file offset will remaind unchanged. The <em>errno</em> global variable is set
to indicate the error.</td>
</tr>
</table>
<br>
<br>
<h3>Error Conditions</h3>
<p>If <strong>fclear()</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>
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EAGAIN">EAGAIN</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</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#ECONVERT">ECONVERT</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#EFBIG">EFBIG</a>]</em></td>
<td align="left" valign="top">
<p>The size of the file would exceed 2GB minus 1 bytes when the file is <b>not</b>
opened for large file access, the system allowed maximum file size when the file
is opened for large file access, or the process soft file size limit.</p>
</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">
&nbsp;
</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#EJRNDAMAGE">EJRNDAMAGE</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EJRNINACTIVE">EJRNINACTIVE</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EJRNRCVSPC">EJRNRCVSPC</a>]</em></td>
<td align="left" valign="top">
&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ENEWJRN">ENEWJRN</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ENEWJRNRCV">ENEWJRNRCV</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#ENOSPC">ENOSPC</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#ERESTART">ERESTART</a>]</em></td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ETRUNC">ETRUNC</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>
<br>
<p>Additionally, 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#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;</tr>
</table>
<br>
<br>
<h3>Error Messages</h3>
<p>The following messages may be sent from this function:</p>
<table width="100%" cellpadding="5">
<!-- cols="15 85" -->
<tr>
<th align="left" valign="top">Message ID</th>
<th align="left" valign="top">Error Message Text</th>
</tr>
<tr>
<td width="15%" valign="top">CPE3418 E</td>
<td width="85%" 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:<br>
<br>
<ul>
<li>Where multiple threads exist in the job.<br>
<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>QFileSvr.400</li>
<li>Network File System</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 operating is a save file and multiple threads exist in the
job.</p>
<p>An <b>fclear()</b> request should not be done on a save file. If it is,
unpredictable results may occur.</p>
<p>A successful <strong>fclear()</strong> updates the change, modification, and
access times for a database member using the normal rules that apply to
database files. At most, the access time is updated once per day.</p>
<br>
</li>
<li>QOPT File System Differences
<p>The change and modification times of the file are updated when the file is
closed.</p>
<p>When writing to files on volumes formatted in Universal Disk Format (UDF),
byte locks on the range being cleared are ignored.</p>
</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, writing, and clearing of files with the Network File System relies on
byte-range locking to guarantee data integrity. To prevent data inconsistency,
use the <a href="fcntl.htm">fcntl()</a> API to get and release these locks.</p>
</li>
<li>QFileSvr.400 File System Differences
<p>This file system does not support <strong>fclear()</strong> or
<strong>fclear64()</strong>, [ENOTSUP] will be returned.</p>
</li>
<li><img src="delta.gif" alt="Start of change">QNTC File System Differences
<p>This file system does not support <strong>fclear()</strong> or
<strong>fclear64()</strong>, [ENOTSUP] will be returned.
<img src="deltaend.gif" alt="End of change"></p></li>
<li>File System Differences
<p>File systems other than "root" (/), QOpenSys, user-defined,
<img src="delta.gif" alt="Start of change">QNTC and QFileSvr.400
<img src="deltaend.gif" alt="End of change">
will be restricted
to doing <b>fclear()</b>s no larger than 2GB minus 1 bytes. If this rule
is violated [EINVAL] will be returned. </p></li>
<li>For the file systems that do not support large files,
<strong>fclear()</strong> will return [EINVAL] if <em>nbyte</em>
plus the file offset exceeds 2GB minus 1 bytes, regardless of how the file was opened.
For the file systems
that do support large files, <strong>fclear()</strong> will return [EFBIG] if
<em>nbyte</em>
plus the file offset exceeds 2GB minus 1 bytes and the file was not opened for
large file access.<br>
<br>
</li>
<li>If the <b>fclear()</b> exceeds the
process soft file size limit, signal SIFXFSZ is issued.</li>
</ol>
<br>
<h3>Related Information</h3>
<ul>
<li>The &lt;<strong>fcntl.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="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="ftruncat.htm">ftruncate()</a>--Truncate File
</li>
<li><a href="ftrunc64.htm">ftruncate64()</a>--Truncate File (Large File Enabled)
</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="read.htm">read()</a>--Read from Descriptor
</li>
<li><a href="readv.htm">readv()</a>--Read from Descriptor Using Multiple
Buffers
</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 clears a specific number of bytes in a file:</p>
<pre>
#include &lt;unistd.h&gt;
#include &lt;stdio.h&gt;
main() {
int fileDescriptor;
off_t ret;
int oflags = O_CREAT | O_RDWR;
mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR;
if ((fileDescriptor = open("foo", oflags, mode)) &lt; 0)
perror("open() error");
else {
if ((ret = fclear(fileDescriptor, 10)) == -1)
perror("fclear() error");
else printf("fclear() cleared %d bytes.\n", ret);
if (close(fileDescriptor)!= 0)
perror("close() error");
if (unlink("foo")!= 0)
perror("unlink() error");
}
}
</pre>
<p><strong>Output:</strong></p>
<pre>
fclear() cleared 10 bytes.
</pre>
<br>
<hr>
<p>API introduced: V5R3</p>
<hr>
<table align="center" 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>
</body>
</html>