QlgOpendir()--Open Directory (using NLS-enabled path name)


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

 DIR *QlgOpendir(Qlg_Path_Name_T *dirname);  
  Service Program Name: QP0LLIB1

  Default Public Authority: *USE

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

The QlgOpendir() function, like the opendir() function, opens a directory so it can be read. The difference is that the QlgOpendir() function takes a pointer to a Qlg_Path_Name_T structure, while the opendir() function takes a pointer to a character string. The QlgOpendir() function opens a directory so it can be read with the QlgReaddir() function.

Names returned on calls to QlgReaddir() are returned in the coded character set identifier (CCSID) specified at the time the directory is opened. QlgOpendir() allows the CCSID to be specified in the Qlg_Path_Name_T structure. opendir() uses the CCSID that is in effect for the current job at the time the opendir() function is called. See opendir()--Open Directory for more on the job CCSID.

Limited information on the dirname parameter is provided here. For more information on the dirname parameter and for a discussion of authorities required, return values, and related information, see opendir()--Open Directory.


Parameters

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

Related Information


Example

The following example opens a 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 <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>

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 >=   */
                             /* 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*)&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 < indent; count++) printf("  ");
  printf("%s\n", fn);

  if ((dir = QlgOpendir((Qlg_Path_Name_T *)&path)) == NULL)
    perror("QlgOpendir() error");
  else
  {
    path_to_stat = path;
 
    while ((entry = QlgReaddir(dir)) != NULL)
    {

      if
        (entry->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->d_lg_name,entry->d_lg_qlg.Path_Length);

        strcat(path_to_stat.pn,(char *)&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->d_lg_qlg.Path_Length + 1);
         
 
        /* Call QlgStat() to determine if the path name   */
        /* is a directory.                                */
        if (QlgStat((Qlg_Path_Name_T *)&path_to_stat,
                    &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);
}

Output:

Directory structure:
/etc
  /etc/samples
    /etc/samples/IBM
  /etc/IBM

API introduced: V5R1

[ Back to top | UNIX-Type APIs | APIs by category ]