QlgReaddir_r()--Read Directory Entry (using NLS-enabled path name)


  Syntax
 #include <sys/types.h>
 #include <dirent.h>

 int QlgReaddir_r(DIR *dirp, struct dirent_lg *entry,  
                  struct dirent_lg **result);  
  Service Program Name: QP0LLIBTS

  Default Public Authority: *USE

  Threadsafe: Conditional; see Usage Notes for readdir_r().

The QlgReaddir_r() function, like the readdir_r() function, initializes a structure that is referenced by entry to represent the next directory entry in the directory stream that is associated with dirp. The difference is that the QlgReaddir_r() dirp parameter points to a dirent_lg structure, while the readdir_r() dirp parameter points to a dirent structure.

The QlgReaddir_r functions stores a pointer to the entry structure at the location referenced by result.

Limited information on the dirp parameter, the entry parameter, and the result parameter is provided here. For more information on these parameters and for a discussion of authorities required, return values, and related information, see readdir_r()--Read Directory Entry.


Parameters

dirp
(Input) A pointer to a DIR that refers to the open directory stream to be read. This pointer is returned by QlgOpendir().

entry
(Output) A pointer to a dirent_lg structure in which the directory entry is to be placed.

result
(Output) A pointer to a pointer to a dirent_lg structure. Upon successfully reading a directory entry, this dirent_lg pointer is set to the same value as entry. Upon reaching the end of the directory stream, this pointer is set to NULL.

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 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 Path name format.

Related Information


Example

See Code disclaimer information for information pertaining to code examples.

The following example reads the contents of a root directory:

#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <stdio.h>

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 >=   */
                         /* 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*)&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:");
    for (return_code = QlgReaddir_r(dir, &entry, &result);
         result != NULL && return_code == 0;
         return_code = QlgReaddir_r(dir, &entry, &result))
      printf("  %s\n", entry.d_lg_name);
    if (return_code != 0)
      perror("QlgReaddir_r() error");
    closedir(dir);
  }
}

Output:

contents of root:
  .
  ..
  QSYS.LIB
  QDLS
  QOpenSys
  QOPT
  home

API introduced: V5R1
Top | UNIX-Type APIs | APIs by category