ooppeennddiirr() -- General Function (libc)

Open a directory stream
#iinncclluuddee <ssyyss/ttyyppeess.hh>
#iinncclluuddee <ddiirreenntt.hh>
DDIIRR *ooppeennddiirr (_d_i_r_n_a_m_e)
cchhaarr *_d_i_r_n_a_m_e;

The COHERENT function  ooppeennddiirr() is one of a set  of COHERENT routines that
manipulate  directories  in   a  device-independent  manner.   It  opens  a
directory stream and connects the directory _d_i_r_n_a_m_e with it.

ooppeennddiirr() returns  a pointer  to the directory  stream it has  created.  It
returns NULL if it cannot access _d_i_r_n_a_m_e, if _d_i_r_n_a_m_e is not a directory, or
if  it cannot  create  the directory  stream (perhaps  due to  insufficient
memory).

If an error occurs, ooppeennddiirr() exits and sets eerrrrnnoo to an appropriate value.

_E_x_a_m_p_l_e
The following example searches the current working directory for entry FFOOOO:

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

    main()
    {
        DIR *dirp
        struct dirent *dp;

        dirp = opendir( "." );

        while ((dp = readdir( dirp )) != NULL ) {
            if ( strcmp( dp->d_name, "FOO" ) == 0 ) {
                printf("Found FOO\n");
                (void) closedir(dirp);
                return FOUND;
            }
        }

        (void) closedir( dirp );
        printf("FOO not found\n");
        return NOT_FOUND;
    }

_S_e_e _A_l_s_o
cclloosseeddiirr(), ddiirreenntt.hh, ggeettddeennttss(),  lliibbcc, rreeaaddddiirr(), rreewwiinnddddiirr(), sseeeekkddiirr(),
tteellllddiirr()
POSIX Standard, section 5.1.2

_N_o_t_e_s
The ddiirreenntt  routines buffer directories; and  because directory entries can
appear  and  disappear  as  other  users  manipulate  the  directory,  your
application  should continually  rescan  a directory  to  keep an  accurate
picture of its active entries.

The COHERENT implementation of the ddiirreenntt routines was written by D. Gwynn.
