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

166 lines
5.1 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>QlgCreat()--Create or Rewrite File (using NLS-enabled path name)</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 -->
<!-- Created by Yvonne Griffin for V5R1-->
<!-- Change History: -->
<!-- 011022 JTROUS Changes from API Review 1, V5R2 -->
<!-- This file has undergone html cleanup June 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>QlgCreat()--Create or Rewrite File (using NLS-enabled path name)</h2>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;fcntl.h&gt;
int QlgCreat(Qlg_Path_Name_T <em>*path</em>, mode_t <em>mode</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 Usage Notes for <a
href="open.htm">open()</a>.<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>QlgCreat()</strong> function, like the <strong>creat()</strong>
function, creates a new file or rewrites an existing file so that it is
truncated to zero length. The difference is that the <strong>
QlgCreat()</strong> function takes a pointer to a Qlg_Path_Name_T structure,
while <strong>creat()</strong> takes a pointer to a character string. See <a
href="open.htm">open()</a>--Open File for more details on how the function
call</p>
<pre>
QlgCreat(<em>path,mode</em>);
</pre>
is equivalent to the call
<pre>
QlgOpen(<em>path</em>, O_CREAT|O_WRONLY|O_TRUNC, <em>mode</em>);
</pre>
<p>Limited information on the <em>path</em> parameter is provided here. For
more information on the <em>path</em> parameter and for a discussion of other
parameters, authorities required, return values, and related information, see
<a href="creat.htm">creat()</a>--Create or Rewrite File or <a href="open.htm">
open()</a>--Open File.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong><em>path</em></strong></dt>
<dd>(Input) A pointer to a Qlg_Path_Name_T structure that contains a path name
or a pointer to a path name of the file to be created or rewritten. For more
information on the Qlg_Path_Name_T structure, see <a href="../apiref/pns.htm">Path name
format</a>.</dd>
</dl>
<br>
<h3>Related Information</h3>
<ul>
<li><a href="creat.htm">creat()</a>--Create or Rewrite File<br>
<br>
</li>
<li><a href="creat64u.htm">QlgCreat64()</a>--Create or Rewrite a File (large
file enabled and using NLS-enabled path name)</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 creates a file:</p>
<pre>
#include &lt;stdio.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;Qp0lstdi.h&gt;
main() {
char text[]="This is a test";
int file_descriptor;
#define mypath "creat.file"
const char US_const[3]= "US";
const char Language_const[4] ="ENU";
typedef struct pnstruct
{
Qlg_Path_Name_T qlg_struct;
char pn[100]; /* This array size must be &gt;= the */
/* length of the path name or this must */
/* be a pointer to the path name. */
};
struct pnstruct path;
/***************************************************************/
/* Initialize Qlg_Path_Name_T parameters */
/***************************************************************/
memset((void*)&amp;path, 0x00, sizeof(struct pnstruct));
path.qlg_struct.CCSID = 37;
memcpy(path.qlg_struct.Country_ID,US_const,2);
memcpy(path.qlg_struct.Language_ID,Language_const,3);
path.qlg_struct.Path_Type = QLG_CHAR_SINGLE;
path.qlg_struct.Path_Length = sizeof(mypath)-1;
path.qlg_struct.Path_Name_Delimiter[0] = '/';
memcpy(path.pn,mypath,sizeof(mypath)-1);
if ((file_descriptor =
QlgCreat((Qlg_Path_Name_T *)&amp;path, S_IRUSR | S_IWUSR)) &lt; 0)
perror("QlgCreat() error");
else {
write(file_descriptor, text, strlen(text));
close(file_descriptor);
QlgUnlink((Qlg_Path_Name_T *)&amp;path);
}
}
</pre>
<hr>
API introduced: V5R1
<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>