QlgReaddir()--Read Directory Entry (using NLS-enabled path name)
Syntax
#include <sys/types.h> #include <dirent.h> struct dirent_lg *QlgReaddir(DIR *dirp);Service Program Name: QP0LLIB1
Default Public Authority: *USE
Threadsafe: No; see Usage Notes for readdir().
The QlgReaddir() function, like the readdir() function, returns a pointer to a structure describing the next directory entry in the directory stream associated with dirp. The difference is that the QlgReaddir() function returns a pointer to a dirent_lg structure, while readdir() returns a pointer to a dirent structure.
The QlgReaddir() function converts the directory entry name into the CCSID (coded character set identifier) of the job at the time of the call to opendir(), or to the CCSID specified on the call to QlgOpendir(). If the directory entry name cannot be represented in that CCSID, then that directory entry will not be returned by QlgReaddir() and no error indication will occur.
QlgOpendir() allows the CCSID to be specified in the Qlg_Path_Name_T structure. See QlgOpendir()--Open Directory (using NLS-enabled path name) for more information.
Limited information about the dirp parameter is provided here. For more information about the dirp parameter and for a discussion of authorities required, and related information, see readdir()--Read Directory Entry.
Parameters
- dirp
- (Input) A pointer to DIR that refers to the open directory stream to be read. This pointer is returned by QlgOpendir() or opendir().
Return Value
- value
- QlgReaddir() was successful. The value returned is a pointer
to a dirent_lg structure describing the next directory entry in the
directory stream.
A dirent_lg structure has the following contents:
char d_reserved1[16] Reserved. unsigned int d_fileno_gen_id The generation ID associated with the file ID. ino_t d_fileno The file ID of the file. This number uniquely identifies the object within a file system. unsigned int d_reclen The length of the directory entry in bytes. int d_reserved3 Reserved. char d_reserved4[6] Reserved. char d_reserved5[2] Reserved. Qlg_Path_Name_T d_lg_name A Qlg_Path_Name_T 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 about the Qlg_Path_Name_T structure, see Path name format. - NULL pointer
- One of the following has occurred:
- QlgReaddir() reached the end of the directory stream. The errno global variable is not changed.
- QlgReaddir() was not successful. The errno is set.
Related Information
- The <sys/types.h> file (see Header Files for UNIX®-Type Functions)
- The <dirent.h> file see Header Files for UNIX-Type Functions)
- readdir()--Read Directory Entry
- readdir_r()--Read Directory Entry
- QlgReaddir_r()--Read Directory Entry (using NLS-enabled path name)
- readdir_r_ts64()--Read Directory Entry
- opendir()--Open Directory
- QlgOpendir()--Open Directory (using NLS-enabled path name)
- rewinddir()--Reset Directory Stream to Beginning
- closedir()--Close Directory
- pathconf()--Get Configurable Path Name Variables
- QlgPathconf()--Get Configurable Path Name Variables (using NLS-enabled path name)
Example
The following example reads the contents of a root directory.
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
main() {
typedef struct my_dirent_lg
{
struct dirent_lg *entry;
char d_lg_name[1];
};
struct my_dirent_lg lg_struct;
struct dirent_lg *entry;
#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 >= */
/* the length of the path name */
/* or this must be a pointer */
/* to the path name. */
};
struct pnstruct path;
DIR *dir;
/***************************************************************/
/* Initialize Qlg_Path_Name_T parameters */
/***************************************************************/
memset((void*)&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 *)&path)) == NULL)
perror("QlgOpendir() error");
else {
puts("contents of root:");
while ((entry = QlgReaddir(dir)) != NULL)
printf(" %s\n", entry->d_lg_name);
closedir(dir);
}
}
Output:
contents of root: . .. QSYS.LIB QDLS QOpenSys QOPT home
API introduced: V5R1