     **
     ** Program summary
     ** ---------------
     **
     ** Unix type APIs:
     **
     **   opendir     Open directory        Opens a directory so that it can be
     **                                     read with the readdir function and
     **                                     returns a pointer to be used by
     **                                     subsequent dir operations
     **
     **   readdir     Read directory entry  Reads the directory entries one by
     **                                     one returning a pointer to a dirent
     **                                     structure describing each entry
     **
     **   closedir    Close directory       Closes the directory stream and
     **                                     frees the buffer used by readdir
     **
     **   lstat       Get file or link      Gets status information about the
     **               information           specified directory entry and puts
     **                                     it in the structure pointed to by
     **                                     the pBuf parameter
     **
     **   getpwuid    Get user information  Returns information describing the
     **               for user ID           user identified by the uid parameter
     **
     **
     ** C library functions:
     **
     **   localtime   Convert time          Converts a time value to a structure
     **                                     of type tm - see definition below
     **
     **   ctime       Convert time to       Converts a time value to local time
     **               character string      in the form of a character string
     **
     **
     ** Sequence of events:
     **
     **   1. The specified directory is opened   - failure returns a null value
     **
     **   2. All directory entries are read      - end of directory signalled by
     **                                            null value
     **
     **   3. For each entry read attributes      - failure indicated by -1
     **      are retrieved and:
     **       - time values are converted by
     **         localtime and ctime
     **       - user names are retrieved by
     **         getpwuid
     **
     **   4. The opened directory is closed      - failure indicated by -1
     **
     **
     ** Compile options:
     **
     **   CRTBNDRPG ...  DBGVIEW(*LIST)
     **
     **
     **-- Control spec:  -----------------------------------------------------**
     H Option( *SrcStmt )  DftActGrp( *No )  BndDir( 'QC2LE' )
     **-- Global variables:  -------------------------------------------------**
     D RtnCod          s             10i 0
     D DirNam          s             64a   Inz( '/QTCPTMM' )
     D Time            s             24a
     D User            s             10a
     **-- Dir entry-structure:  ----------------------------------------------**
     D DirEnt          Ds                  Based( pDirEnt )  Align
     D  d_reserved1                  16a
     D  d_filenogenid                10u 0
     D  d_fileno                     10u 0
     D  d_reclen                     10u 0
     D  d_reserved3                  10i 0
     D  d_reserved4                   6a
     D  d_reserved5                   2a
     D  d_nlsinfo
     D   d_ccsid                     10i 0 Overlay( d_nlsinfo:  1 )
     D   d_country_id                 2a   Overlay( d_nlsinfo:  5 )
     D   d_lang_id                    3a   Overlay( d_nlsinfo:  7 )
     D   d_nls_reserv                 3a   Overlay( d_nlsinfo: 10 )
     D  d_namelen                    10u 0
     D  d_name                      640a
     **
     D pDir            s               *
     **-- File stat-structure:  ----------------------------------------------**
     D Buf             Ds                  Align
     D  st_mode                      10u 0                                      File permissions
     D  st_ino                       10u 0                                      File id
     D  st_nlink                      5u 0                                      Number of links
     D                                2a
     D  st_uid                       10u 0                                      File user id
     D  st_gid                       10u 0                                      File group id
     D  st_size                      10i 0                                      Size in bytes
     D  st_atime                     10i 0                                      File last accessed
     D  st_mtime                     10i 0                                      Data last changed
     D  st_ctime                     10i 0                                      Status last changed
     D  st_dev                       10u 0                                      File system id
     D  st_blksize                   10u 0                                      Blocksize in bytes
     D  st_allocsize                 10u 0                                      Bytes allocated
     D  st_objtype                   11a                                        Object type
     D                                1a
     D  st_codepage                   5u 0                                      Codepage
     D  st_reserv1                   62a
     D  st_ino_gen_id                10u 0                                      File generation id
     **
     D pBuf            s               *   Inz( %Addr( Buf ))
     **-- Time tm-structure:  ------------------------------------------------**
     D Tm              Ds                  Based( pTm )
     D  tm_sec                       10i 0                                      Seconds (0-61)
     D  tm_min                       10i 0                                      Minutes (0-59)
     D  tm_hour                      10i 0                                      Hours   (0-23)
     D  tm_mday                      10i 0                                      Day of month (1-31)
     D  tm_mon                       10i 0                                      Month   (0-11)
     D  tm_year                      10i 0                                      Year    (-1900)
     D  tm_wday                      10i 0                                      Day of week  (0-6)
     D  tm_yday                      10i 0                                      Day of year  (0-365)
     D  tm_isdst                     10i 0                                      DST in effect
     **-- Passwd structure:  -------------------------------------------------**
     D Passwd          Ds                  Based( pPasswd )  Align
     D  pw_name                        *
     D  pw_uid                       10u 0
     D  pw_gid                       10u 0
     D  pw_dir                         *
     D  pw_shell                       *
     **-- Directory functions:  ----------------------------------------------**
     D opendir         Pr              *   ExtProc( 'opendir' )
     D                                 *   Value  Options( *String )
     **
     D readdir         Pr              *   ExtProc( 'readdir' )
     D                                 *   Value
     **
     D closedir        Pr            10i 0 ExtProc( 'closedir' )
     D                                 *   Value
     **-- File functions:  ---------------------------------------------------**
     D lstat           Pr            10i 0 ExtProc( 'lstat' )
     D                                 *   Value  Options( *String )
     D                                 *   Value
     **-- Time functions:  ---------------------------------------------------**
     D localtime       Pr              *   ExtProc( 'localtime' )
     D                               10i 0 Const
     **
     D ctime           Pr              *   ExtProc( 'ctime' )
     D                               10i 0 Const
     **-- User functions:  ---------------------------------------------------**
     D getpwuid        Pr              *   ExtProc( 'getpwuid' )
     D                               10u 0 Value
     **
     **-- Retrieve directory entry attributes:  ------------------------------**
     **
     C                   Eval      pDir       =  opendir( %TrimR( DirNam ))
     C                   Eval      pDirEnt    =  readdir( pDir )
     **
     C                   DoW       pDirEnt    <> *Null
     **
     C                   If        lstat( %TrimR( DirNam )    + '/'  +
     C                                    %Str( %Addr( d_name ))
     C                                  : pBuf
     C                                  )     <> -1
     **
     **-- Extract time attributes - tm-structure:
     C                   Eval      pTm        =  localtime( st_atime )
     C                   Eval      pTm        =  localtime( st_mtime )
     C                   Eval      pTm        =  localtime( st_ctime )
     **
     **-- Extract time attributes - formatted string:
     C                   Eval      Time       =  %Str( ctime( st_atime ))
     C                   Eval      Time       =  %Str( ctime( st_mtime ))
     C                   Eval      Time       =  %Str( ctime( st_ctime ))
     **
     C                   Eval      pPasswd    =  getpwuid( st_uid )
     C                   Eval      User       =  %Str( pw_name  )
     **
     C                   EndIf
     **
     C                   Eval      pDirEnt    =  readdir( pDir )
     C                   EndDo
     **
     C                   Eval      RtnCod     =  closedir( pDir )
     **
     C                   Return
     **
