xref: /386bsd/usr/share/man/cat3/scandir.0 (revision a2142627)
1SCANDIR(3)                386BSD Programmer's Manual                SCANDIR(3)
2
3NNAAMMEE
4     ssccaannddiirr, aallpphhaassoorrtt - scan a directory
5
6SSYYNNOOPPSSIISS
7     ##iinncclluuddee <<ssyyss//ttyyppeess..hh>>
8     ##iinncclluuddee <<ddiirreenntt..hh>>
9
10     _i_n_t
11     ssccaannddiirr(_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,
12             _i_n_t (*_s_e_l_e_c_t)(_s_t_r_u_c_t _d_i_r_e_n_t *),
13             _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 *))
14
15     _i_n_t
16     aallpphhaassoorrtt(_c_o_n_s_t _v_o_i_d *_d_1, _c_o_n_s_t _v_o_i_d *_d_2)
17
18DDEESSCCRRIIPPTTIIOONN
19     The ssccaannddiirr() function reads the directory _d_i_r_n_a_m_e and builds an array of
20     pointers to directory entries using malloc(3).  It returns the number of
21     entries in the array.  A pointer to the array of directory entries is
22     stored in the location referenced by _n_a_m_e_l_i_s_t.
23
24     The _s_e_l_e_c_t parameter is a pointer to a user supplied subroutine which is
25     called by ssccaannddiirr() to select which entries are to be included in the
26     array.  The select routine is passed a pointer to a directory entry and
27     should return a non-zero value if the directory entry is to be included
28     in the array.  If _s_e_l_e_c_t is null, then all the directory entries will be
29     included.
30
31     The _c_o_m_p_a_r parameter is a pointer to a user supplied subroutine which is
32     passed to qsort(3) to sort the completed array.  If this pointer is null,
33     the array is not sorted.
34
35     The aallpphhaassoorrtt() function is a routine which can be used for the _c_o_m_p_a_r
36     parameter to sort the array alphabetically.
37
38     The memory allocated for the array can be deallocated with free(3),  by
39     freeing each pointer in the array and then the array itself.
40
41DDIIAAGGNNOOSSTTIICCSS
42     Returns -1 if the directory cannot be opened for reading or if malloc(3)
43     cannot allocate enough memory to hold all the data structures.
44
45SSEEEE AALLSSOO
46     directory(3),  malloc(3),  qsort(3),  dir(5)
47
48HHIISSTTOORRYY
49     The ssccaannddiirr() and aallpphhaassoorrtt() functions appeared in 4.2BSD.
50
514.2 Berkeley Distribution       April 19, 1991                               1
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67