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

161 lines
5.1 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>pwrite64()--Write to Descriptor with Offset (large file enabled)</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. -->
<!-- Change History: -->
<!-- YYMMDD USERID Change description -->
<!-- Unix2 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
<!-- 010308 JTROUS Creation date based on pwrite, for V5R2, DCR 98686 -->
<!-- 011022 JTROUS Changes from API Review 1, V5R2 -->
<!-- 030730 VONBERGE Remove QSYS.LIB comment about offset/text mode. -->
<!-- It was moved to file system diffs in pwrite.htm. -->
<!-- This file has undergone html cleanup May 2002 by JET -->
<!-- End Header Records -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<!-- Java sync-link -->
<script language="Javascript" src="../rzahg/synch.js" type="text/javascript">
</script>
<a name="Top_Of_Page"></a>
<h2 id="HDRPWRITE64">pwrite64()--Write to Descriptor with Offset (large file
enabled)</h2>
<div class="box" style="width: 70%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;unistd.h&gt;
ssize_t pwrite64
(int <em>file_descriptor</em>, const void <em>*buf</em>,
size_t <em>nbyte</em>, off64_t <em>offset</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>The <strong>pwrite64()</strong> function writes <em>nbyte</em> bytes from
<em>buf</em> to the file associated with <em>file_descriptor</em>. The <em>
offset</em> value defines the starting position in the file and the file
pointer position is not changed.</p>
<p>The <em>offset</em> will also be ignored if <em>file_descriptor</em> refers
to a descriptor obtained using the <strong>open()</strong> function with
O_APPEND specified.</p>
<p><strong>pwrite64()</strong> is enabled for large files. It is capable of
operating on files larger than 2GB minus 1 byte as long as the file has been
opened by either of the following:</p>
<ul>
<li>Using the <strong>open64()</strong> function (see <a href="open64.htm">
open64()--Open File (large file enabled)</a>).</li>
<li>Using the <strong>open()</strong> function (see <a href="open.htm">
open()--Open File</a>) with O_LARGEFILE set in the oflag parameter.</li>
</ul>
<p>For additional information about parameters, authorities, and error
conditions, see <a href="pwrite.htm">pwrite()--Write to Descriptor with
Offset</a>.</p>
<br>
<h3><a name="usage_notes">Usage Notes</a></h3>
<ol type="1">
<li>When you develop in C-based languages, the prototypes for the 64-bit APIs
are normally hidden. To use the <strong>pwrite64</strong> API, you must compile
the source with the _LARGE_FILE_API macro defined.</li>
<li>All of the usage notes for <strong>pwrite()</strong> apply to <strong>
pwrite64()</strong>. See <em>Usage Notes</em> in the <strong>pwrite</strong>
API.</li>
</ol>
<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 writes a specific number of bytes to a file:</p>
<pre>
#define _LARGE_FILE_API
#include &lt;unistd.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#define mega_string_len 1000000
main() {
char *mega_string;
int file_descriptor;
int ret;
off64_t off=5;
char fn[]="write.file";
if ((mega_string = (char*) malloc(mega_string_len+off)) == NULL)
perror("malloc() error");
else if ((file_descriptor = creat64(fn, S_IWUSR)) &lt; 0)
perror("creat64() error");
else {
memset(mega_string, '0', mega_string_len);
if ((ret = pwrite64(file_descriptor, mega_string, mega_string_len, off)) == -1)
perror("pwrite64() error");
else printf("pwrite64() wrote %d bytes at offset %d\n", ret, off);
if (close(file_descriptor)!= 0)
perror("close() error");
if (unlink(fn)!= 0)
perror("unlink() error");
}
free(mega_string);
}
</pre>
<p><strong>Output:</strong></p>
<pre>
pwrite64() wrote 1000000 bytes at offset 5
</pre>
<hr>
API introduced: V5R2
<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>