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

176 lines
5.4 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>QlgFtok()--Generate IPC Key from File Name (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 for V5R1-->
<!-- Edited by Kersten Feb 02 -->
<!-- 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 type="text/javascript" language="Javascript" src="../rzahg/synch.js">
</script>
<a name="Top_Of_Page"></a>
<h2>QlgFtok()--Generate IPC Key from File Name (using NLS-enabled path
name)</h2>
<div class="box" style="width: 90%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;sys/ipc.h&gt;
#include &lt;qlg.h&gt;
key_t QlgFtok(const Qlg_Path_Name_T <em>*path</em>, int <em>id</em>);
</pre>
<br>
&nbsp;&nbsp;Service Program Name: QP0ZCPA<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Conditional. See Usage Notes for <a href="p0zftok.htm">ftok()--Generate IPC Key from File Name</a>.<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>QlgFtok()</strong> function, like the <strong>ftok()</strong>
function, generates an IPC key based on the combination of <em>path</em> and
<em>id</em>. The difference is that the <strong>QlgFtok()</strong> function
takes a pointer to a Qlg_Path_Name_T structure, while the <strong>
ftok()</strong> function takes a pointer to a character string.</p>
<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, returnvalues, and related information, see <a
href="p0zftok.htm">ftok()--Generate IPC Key from File Name</a>.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong>path</strong></dt>
<dd>(Input) The path name of the file used in combination with <em>id</em> to
generate the key. 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>
<p><a href="p0zftok.htm">ftok()</a>--Generate IPC Key from File Name</p>
<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 uses the <strong>QlgFtok()</strong> and <strong>
semget()</strong> functions.</p>
<pre>
#include &lt;sys/ipc.h&gt;
#include &lt;sys/sem.h&gt;
#include &lt;errno.h&gt;
#include &lt;stdio.h&gt;
#include &lt;qlg.h&gt;
int main(int argc, char *argv[])
{
key_t myKey;
int semid;
#define mypath "/myApplication/myFile"
const char US_const[3]= "US";
const char Language_const[4]="ENU";
const char Path_Name_Del_const[2]= "/";
typedef struct pnstruct
{
Qlg_Path_Name_T qlg_struct;
char[100] pn; /* This size must be &gt;= the path */
/* name length or be a pointer */
/* to the path name. */
};
struct pnstruct path;
/***************************************************************/
/* Initialize Qlg_Path_Name_T parameters */
/***************************************************************/
memset((void*)path name, 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;
memcpy(path.qlg_struct.Path_Name_Delimiter,Path_Name_Del_const,1);
memcpy(path.pn,mypath,sizeof(mypath));
/* Use QlgFtok to generate a key associated with a file. */
/* Every process will get the same key back if the caller */
/* calls with the same parameters. */
myKey = QlgFtok((Qlg_Path_Name_T *)path name, 42);
if(myKey == -1) {
printf("QlgFtok failed with errno = %d\n", errno);
return -1;
}
/* Call an xxxget() API, where xxx is sem, shm, or msg. */
/* This will create or reference an existing IPC object */
/* with the 'well known' key associated with the file */
/* name used above. */
semid = semget(myKey, 1, 0666 | IPC_CREAT);
if(semid == -1) {
printf("semget failed with errno = %d\n", errno);
return -1;
}
/* ... Use the semaphore as required ... */
return 0;
}
</pre>
<br>
<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>