     **
     ** 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 second 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
     **
     ** QP0Z_CVTTIME_TO_OFFSET             0
     ** QP0Z_CVTTIME_TO_TIMESTAMP          1
     ** QP0Z_CVTTIME_FACTOR_EPOCH_ONLY     2
     ** QP0Z_CVTTIME_FACTOR_UTCOFFSET_ONLY 3
     **
     **   struct timeval 
     **      long  tv_sec;                  /* second                        */
     **      long  tv_usec;                 /* microseconds                  */
     **    ;
     **
     **
     ** 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( '/qopensys/camp/availability-
     D                                     /NOVASOL' )
     D TS              s               z
     D Time            s             24a
     D User            s             10a
     D rc              s             10i 0
     D MI_Time         s              8a
     D MI_DTS          s             20a
     D ErrTxt          s            128a
     **-- 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: *Next )
     D   d_lang_id                    3a   Overlay( d_nlsinfo: *Next )
     D   d_nls_reserv                 3a   Overlay( d_nlsinfo: *Next )
     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
     **-- Time tm-structure:  ------------------------------------------------**
     D timeval         Ds                  Qualified
     D  sec                          10i 0                                      Seconds (0-61)
     D  usec                         10i 0                                      Seconds (0-61)
     **-- 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
     **
     D rename          Pr            10i 0 ExtProc( 'Qp0lRenameUnlink' )
     D                                 *   Value  Options( *String )
     D                                 *   Value  Options( *String )
     **-- Time functions:  ---------------------------------------------------**
     D localtime       Pr              *   ExtProc( 'localtime' )
     D                               10i 0 Const
     **
     D ctime           Pr              *   ExtProc( 'ctime' )
     D                               10i 0 Const
     **
     D CvtTvtoMi       Pr            10i 0 ExtProc( 'Qp0zCvtToMITime' )
     D                                 *   Value
     D                                 *   Value
     D                               10i 0 Value
     **-- Convert date & time:  ----------------------------------------------**
     D CvtDtf          Pr                  ExtPgm( 'QWCCVTDT' )
     D  CdInpFmt                     10a   Const
     D  CdInpVar                     17a   Const  Options( *VarSize )
     D  CdOutFmt                     10a   Const
     D  CdOutVar                     17a          Options( *VarSize )
     D  CdError                      10i 0 Const
     **
     **-- User functions:  ---------------------------------------------------**
     D getpwuid        Pr              *   ExtProc( 'getpwuid' )
     D                               10u 0 Value
     **-- Error identification:  ---------------------------------------------**
     D errno           Pr            10i 0
     **
     D strerror        Pr           128a   Varying
     **
     **-- Retrieve directory entry attributes:  ------------------------------**
     **
     **
     C                   If        lstat( %TrimR( DirNam )
     C                                  : %Addr( Buf )
     C                                  )     <> -1
     **
     C                   If        %Str( %Addr( st_objtype )) =  '*STMF '
     **
     C                   Eval      timeval.sec  = st_ctime
     C                   Eval      timeval.usec = *zero
     **
     C                   Eval      rc         = CvtTvToMi( %Addr( MI_Time )
     C                                                   : %Addr( timeval )
     C                                                   : 1
     C                                                   )
     **
     C                   CallP     CvtDtf( '*DTS'
     C                                   : MI_Time
     C                                   : '*YYMD'
     C                                   : MI_DTS
     C                                   : 0
     C                                   )
     **
     C                   Eval      TS  = %Timestamp( MI_DTS: *ISO0 )
     **
     C                   EndIf
     C                   EndIf
     **
     C                   Return
     **
     **-- Get runtime error number:  -----------------------------------------**
     P Errno           B
     D                 Pi            10i 0
     D sys_errno       Pr              *    ExtProc( '__errno' )
     **
     D Error           s             10i 0  Based( pError )  NoOpt
     **
     C                   Eval      pError     =  sys_errno
     C                   Return    Error
     **
     P Errno           E
     **-- Get runtime error text:  -------------------------------------------**
     P Strerror        B
     D                 Pi           128a    Varying
     D sys_strerror    Pr              *    ExtProc( 'strerror' )
     D                               10i 0  Value
     **
     C                   Return    %Str( sys_strerror( Errno ))
     **
     P Strerror        E
