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

268 lines
8.0 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>QlgReaddir_r()--Read Directory Entry (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. -->
<!-- file cleaned -->
<!-- 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>
<a name="Top_Of_Page"></a>
<!--Java sync-link-->
<script language="Javascript" src="../rzahg/synch.js" type="text/javascript">
</script>
<h2>QlgReaddir_r()--Read Directory Entry (using NLS-enabled path name)</h2>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;sys/types.h&gt;
#include &lt;dirent.h&gt;
int QlgReaddir_r(DIR <em>*dirp</em>, struct dirent_lg <em>*entry</em>,
struct dirent_lg <em>**result</em>);
</pre>
&nbsp;&nbsp;Service Program Name: QP0LLIBTS<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Conditional; see Usage Notes for <a href="readdirr.htm">
readdir_r()</a>.<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>QlgReaddir_r()</strong> function, like the <strong>
readdir_r()</strong> function, initializes a structure that is referenced by
<em>entry</em> to represent the next directory entry in the directory stream
that is associated with <em>dirp</em>. The difference is that the <strong>
QlgReaddir_r()</strong> <em>dirp</em> parameter points to a <samp>
dirent_lg</samp> structure, while the <strong>readdir_r()</strong> <em>
dirp</em> parameter points to a <samp>dirent</samp> structure.</p>
<p>The QlgReaddir_r functions stores a pointer to the <em>entry</em> structure
at the location referenced by <em>result</em>.</p>
<p>Limited information on the <em>dirp</em> parameter, the <em>entry</em>
parameter, and the <em>result</em> parameter is provided here. For more
information on these parameters and for a discussion of authorities required,
return values, and related information, see <a href="readdirr.htm">
readdir_r()</a>--Read Directory Entry.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong><em>dirp</em></strong></dt>
<dd>(Input) A pointer to a DIR that refers to the open directory stream to be
read. This pointer is returned by <strong>QlgOpendir()</strong>.<br>
<br>
</dd>
<dt><strong><em>entry</em></strong></dt>
<dd>(Output) A pointer to a <samp>dirent_lg</samp> structure in which the
directory entry is to be placed.<br>
<br>
</dd>
<dt><strong><em>result</em></strong></dt>
<dd>(Output) A pointer to a pointer to a <samp>dirent_lg</samp> structure. Upon
successfully reading a directory entry, this <samp>dirent_lg</samp> pointer is
set to the same value as <em>entry</em>. Upon reaching the end of the directory
stream, this pointer is set to NULL.
<p>A <samp>dirent_lg</samp> structure has the following contents:</p>
<table border>
<tr>
<td align="left" valign="top" width="20%">char</td>
<td align="left" valign="top" width="20%">d_reserved1[16]</td>
<td align="left" valign="top" width="60%">Reserved.</td>
</tr>
<tr>
<td align="left" valign="top">unsigned int</td>
<td align="left" valign="top">d_fileno_gen_id</td>
<td align="left" valign="top">The generation ID associated with the file
ID.</td>
</tr>
<tr>
<td align="left" valign="top">ino_t</td>
<td align="left" valign="top">d_fileno</td>
<td align="left" valign="top">The file ID of the file. This number uniquely
identifies the object within a file system.</td>
</tr>
<tr>
<td align="left" valign="top">unsigned int</td>
<td align="left" valign="top">d_reclen</td>
<td align="left" valign="top">The length of the directory entry in bytes.</td>
</tr>
<tr>
<td align="left" valign="top">int</td>
<td align="left" valign="top">d_reserved3</td>
<td align="left" valign="top">Reserved.</td>
</tr>
<tr>
<td align="left" valign="top">char</td>
<td align="left" valign="top">d_reserved4[6]</td>
<td align="left" valign="top">Reserved.</td>
</tr>
<tr>
<td align="left" valign="top">char</td>
<td align="left" valign="top">d_reserved5[2]</td>
<td align="left" valign="top">Reserved.</td>
</tr>
<tr>
<td align="left" valign="top">Qlg_Path_Name_T</td>
<td align="left" valign="top">d_lg_name</td>
<td align="left" valign="top">A Qlg_Path_Name_T structure that gives the name
of a file in the directory. The path name is not null-terminated within the
structure. The structure also provides National Language Support information,
which includes ccsid, country_id, and language_id. This structure has a maximum
length of {_QP0L_DIR_NAME_LG} bytes. For more information on the
Qlg_Path_Name_T structure, see <a href="../apiref/pns.htm">Path name format</a>.</td>
</tr>
</table>
</dd>
</dl>
<br>
<h3>Related Information</h3>
<ul>
<li><a href="readdir.htm">readdir()</a>--Read Directory Entry<br>
<br>
</li>
<li><a href="opendiru.htm">QlgOpendir()</a>--Open Directory (using NLS-enabled
path name)<br>
<br>
</li>
<li><a href="pathconfu.htm">QlgPathconf()</a>--Get Configurable Path Name
Variables (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 reads the contents of a root directory:</p>
<pre>
#include &lt;sys/types.h&gt;
#include &lt;dirent.h&gt;
#include &lt;errno.h&gt;
#include &lt;stdio.h&gt;
main() {
int return_code;
DIR *dir;
struct dirent_lg entry;
struct dirent_lg *result;
typedef struct my_dirent_lg
{
struct dirent_lg *entry;
char d_lg_name[1];
};
struct my_dirent_lg lg_struct;
#define mypath "/"
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 ((dir = QlgOpendir((Qlg_Path_Name_T *)&amp;path)) == NULL)
perror("QlgOpendir() error");
else {
puts("contents of root:");
for (return_code = QlgReaddir_r(dir, &amp;entry, &amp;result);
result != NULL &amp;&amp; return_code == 0;
return_code = QlgReaddir_r(dir, &amp;entry, &amp;result))
printf(" %s\n", entry.d_lg_name);
if (return_code != 0)
perror("QlgReaddir_r() error");
closedir(dir);
}
}
</pre>
<p><strong>Output:</strong></p>
<pre>
contents of root:
.
..
QSYS.LIB
QDLS
QOpenSys
QOPT
home
</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>