Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <direct.h>
    struct dirent *readdir( struct dirent *dirp );
    struct _wdirent *_wreaddir( _wdirent *dirp );

Description:
    The readdir function obtains information about the next matching file
    name from the argument dirp.  The argument dirp is the value returned
    from the  opendir function.  The readdir function can be called
    repeatedly to obtain the list of file names contained in the directory
    specified by the pathname given to  opendir.  The function  closedir
    must be called to close the directory and free the memory allocated by
     opendir.

    The file <direct.h> contains definitions for the structure  dirent.

    #if defined(__OS2__) || defined(__NT__)
    #define NAME_MAX 255    /* maximum for HPFS or NTFS */
    #else
    #define NAME_MAX  12    /* 8 chars + '.' +  3 chars */
    #endif

    typedef struct dirent {
        char    d_dta[ 21 ];        /* disk transfer area */
        char    d_attr;             /* file's attribute */
        unsigned short int d_time;  /* file's time */
        unsigned short int d_date;  /* file's date */
        long    d_size;             /* file's size */
        char    d_name[ NAME_MAX + 1 ]; /* file's name */
        unsigned short d_ino;       /* serial number */
        char    d_first;            /* flag for 1st time */
    } DIR;
    The _wreaddir function is identical to readdir except that it reads a
    directory of wide-character filenames.

    The file <direct.h> contains definitions for the structure  _wdirent.

    struct _wdirent {
        char    d_dta[21];      /* disk transfer area */
        char    d_attr;         /* file's attribute */
        unsigned short int d_time;/* file's time */
        unsigned short int d_date;/* file's date */
        long    d_size;         /* file's size */
        wchar_t d_name[NAME_MAX+1];/* file's name */
        unsigned short d_ino;   /* serial number (not used) */
        char    d_first;        /* flag for 1st time */
    };

Returns:
    When successful, readdir returns a pointer to an object of type struct
    dirent.  When an error occurs, readdir returns the value NULL and  errno
    is set to indicate the error.  When the end of the directory is
    encountered, readdir returns the value NULL and  errno is unchanged.

    When successful, _wreaddir returns a pointer to an object of type struct
    _wdirent.  When an error occurs, _wreaddir returns the value NULL and
     errno is set to indicate the error.  When the end of the directory is
    encountered, _wreaddir returns the value NULL and  errno is unchanged.

Errors:
    When an error has occurred,  errno contains a value indicating the type
    of error that has been detected.

    EBADF
        The argument dirp does not refer to an open directory stream.


Example:
    To get a list of files contained in the directory \watcom\h on your
    default disk:

    #include <stdio.h>
    #include <direct.h>

    void main()
      {
        DIR *dirp;
        struct dirent *direntp;

        dirp = opendir( "\\watcom\\h" );
        if( dirp != NULL ) {
          for(;;) {
            direntp = readdir( dirp );
            if( direntp == NULL ) break;
            printf( "%s\n", direntp->d_name );
          }
          closedir( dirp );
        }
      }

    Note the use of two adjacent backslash characters (\) within
    character-string constants to signify a single backslash.

Classification:
    readdir is POSIX 1003.1, _wreaddir is not POSIX

Systems:
     readdir - All, Netware

    _wreaddir - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32

See Also:
    closedir, _dos_find Functions, opendir, rewinddir

See Also:

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson