
SCANDIR(3)                 UNIX Programmer's Manual                 SCANDIR(3)

NNAAMMEE
     ssccaannddiirr, aallpphhaassoorrtt - scan a directory

SSYYNNOOPPSSIISS
     ##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>>

     _i_n_t
     ssccaannddiirr(_c_o_n_s_t _c_h_a_r _*_d_i_r_n_a_m_e, _s_t_r_u_c_t _d_i_r_e_n_t _*_*_*_n_a_m_e_l_i_s_t,
             _i_n_t (_*_s_e_l_e_c_t)(_s_t_r_u_c_t _d_i_r_e_n_t _*),
             _i_n_t (_*_c_o_m_p_a_r)(_c_o_n_s_t _v_o_i_d _*_, _c_o_n_s_t _v_o_i_d _*))

     _i_n_t
     aallpphhaassoorrtt(_c_o_n_s_t _v_o_i_d _*_d_1, _c_o_n_s_t _v_o_i_d _*_d_2)

DDEESSCCRRIIPPTTIIOONN
     The ssccaannddiirr() function reads the directory _d_i_r_n_a_m_e and builds an array of
     pointers to directory entries using malloc(3).  It returns the number of
     entries in the array.  A pointer to the array of directory entries is
     stored in the location referenced by _n_a_m_e_l_i_s_t.

     The _s_e_l_e_c_t parameter is a pointer to a user supplied subroutine which is
     called by ssccaannddiirr() to select which entries are to be included in the ar-
     ray.  The select routine is passed a pointer to a directory entry and
     should return a non-zero value if the directory entry is to be included
     in the array.  If _s_e_l_e_c_t is null, then all the directory entries will be
     included.

     The _c_o_m_p_a_r parameter is a pointer to a user supplied subroutine which is
     passed to qsort(3) to sort the completed array.  If this pointer is null,
     the array is not sorted.

     The aallpphhaassoorrtt() function is a routine which can be used for the _c_o_m_p_a_r
     parameter to sort the array alphabetically.

     The memory allocated for the array can be deallocated with free(3),  by
     freeing each pointer in the array and then the array itself.

DDIIAAGGNNOOSSTTIICCSS
     Returns -1 if the directory cannot be opened for reading or if malloc(3)
     cannot allocate enough memory to hold all the data structures.

SSEEEE AALLSSOO
     directory(3),  malloc(3),  qsort(3),  dir(5)

HHIISSTTOORRYY
     The ssccaannddiirr() and aallpphhaassoorrtt() functions appeared in 4.2BSD.

4.2 Berkeley Distribution       April 19, 1991                               1














