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

259 lines
7.9 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>QlgOpendir()--Open Directory (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-->
<!-- 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>QlgOpendir()--Open Directory (using NLS-enabled path name)</h2>
<div class="box" style="width: 70%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;sys/types.h&gt;
#include &lt;dirent.h&gt;
DIR *QlgOpendir(Qlg_Path_Name_T <em>*dirname</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=
"opendir.htm">opendir()</a>.<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>QlgOpendir()</strong> function, like the <strong>
opendir()</strong> function, opens a directory so it can be read. The
difference is that the <strong>QlgOpendir()</strong> function takes a pointer
to a Qlg_Path_Name_T structure, while the <strong>opendir()</strong> function
takes a pointer to a character string. The <strong>QlgOpendir()</strong>
function opens a directory so it can be read with the <strong>
QlgReaddir()</strong> function.</p>
<p>Names returned on calls to <strong>QlgReaddir()</strong> are returned in the
coded character set identifier (CCSID) specified at the time the directory is
opened. <strong>QlgOpendir()</strong> allows the CCSID to be specified in the
Qlg_Path_Name_T structure. <strong>opendir()</strong> uses the CCSID that is in
effect for the current job at the time the <strong>opendir()</strong> function
is called. See <a href="opendir.htm">opendir()</a>--Open Directory for more on
the job CCSID.</p>
<p>Limited information on the <em>dirname</em> parameter is provided here. For
more information on the <em>dirname</em> parameter and for a discussion of
authorities required, return values, and related information, see <a href=
"opendir.htm">opendir()</a>--Open Directory.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong><em>dirname</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 directory to be opened. 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="opendir.htm">opendir()</a>--Open Directory<br>
<br>
</li>
<li><a href="readdiru.htm">QlgReaddir()</a>--Read Directory Entry (using
NLS-enabled path name)<br>
<br>
</li>
<li><a href="spawnu.htm">QlgSpawn()</a>--Spawn Process (using NLS-enabled path
name)<br>
<br>
</li>
<li><a href="spawnpu.htm">QlgSpawnp()</a>--Spawn Process with Path (using
NLS-enabled fileh 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 opens a directory:</p>
<pre>
#include &lt;sys/types.h&gt;
#include &lt;dirent.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;errno.h&gt;
#include &lt;stdio.h&gt;
void traverse(char *fn, int indent) {
DIR *dir;
int count;
struct stat info;
typedef struct my_dirent_lg
{
struct dirent_lg *entry;
char d_lg_name[1];
};
struct my_dirent_lg lg_struct;
struct dirent_lg *entry;
const char US_const[3]= "US";
const char Language_const[4]="ENU";
typedef struct pnstruct
{
Qlg_Path_Name_T qlg_struct;
char pn[1025]; /* 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;
struct pnstruct path_to_stat;
char *temp_char_path[1025];
/***************************************************************/
/* Initialize Qlg_Path_Name_T structure, since the path name */
/* was not in the Qlg_Path_Name_T format when this function */
/* was called. */
/***************************************************************/
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_Name_Delimiter[0] = '/';
path.qlg_struct.Path_Length = strlen(fn);
memcpy(path.pn,fn,strlen(fn));
for (count=0; count &lt; indent; count++) printf(" ");
printf("%s\n", fn);
if ((dir = QlgOpendir((Qlg_Path_Name_T *)&amp;path)) == NULL)
perror("QlgOpendir() error");
else
{
path_to_stat = path;
while ((entry = QlgReaddir(dir)) != NULL)
{
if
(entry-&gt;d_lg_name[0] != '.')
{
/* Concat the components of the path name into a */
/* Qlg_Path_Name_T structure that is used on the */
/* next function that is called. Clear and */
/* use a temporary buffer to ensure that only */
/* characters returned by QlgReaddir() are */
/* included in the concatenated path name */
/* structure. */
strcpy(path_to_stat.pn,path.pn);
strcat(path_to_stat.pn, "/");
memset(temp_char_path, 0x00,1025);
memcpy(temp_char_path,
entry-&gt;d_lg_name,entry-&gt;d_lg_qlg.Path_Length);
strcat(path_to_stat.pn,(char *)&amp;temp_char_path);
/* Calculate the size of the path, including the */
/* length of the path specified on the open, the */
/* length of the name returned by QlgReaddir(), */
/* and the delimiter. */
path_to_stat.qlg_struct.Path_Length =
(path.qlg_struct.Path_Length +
entry-&gt;d_lg_qlg.Path_Length + 1);
/* Call QlgStat() to determine if the path name */
/* is a directory. */
if (QlgStat((Qlg_Path_Name_T *)&amp;path_to_stat,
&amp;info) != 0)
{
fprintf(stderr, "QlgStat() error on %s: %s\n",
path_to_stat.pn,
strerror(errno));
}
else if (S_ISDIR(info.st_mode))
{
/* this a directory so loop to open its objects.*/
traverse(path_to_stat.pn, indent+1);
}
else printf(" %s\n",path_to_stat.pn);
}
}
closedir(dir);
}
}
main() {
puts("Directory structure:");
traverse("/etc", 0);
}
</pre>
<p><strong>Output:</strong></p>
<pre>
Directory structure:
/etc
/etc/samples
/etc/samples/IBM
/etc/IBM
</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>