BSD 4_4 development
[unix-history] / usr / share / man / cat3 / scandir.0
CommitLineData
8bb980a3
C
1SCANDIR(3) BSD Programmer's Manual SCANDIR(3)
2
3N\bNA\bAM\bME\bE
4 s\bsc\bca\ban\bnd\bdi\bir\br, a\bal\blp\bph\bha\bas\bso\bor\brt\bt - scan a directory
5
6S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
7 #\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<s\bsy\bys\bs/\b/t\bty\byp\bpe\bes\bs.\b.h\bh>\b>
8 #\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<d\bdi\bir\bre\ben\bnt\bt.\b.h\bh>\b>
9
10 _\bi_\bn_\bt
11 s\bsc\bca\ban\bnd\bdi\bir\br(_\bc_\bo_\bn_\bs_\bt _\bc_\bh_\ba_\br _\b*_\bd_\bi_\br_\bn_\ba_\bm_\be, _\bs_\bt_\br_\bu_\bc_\bt _\bd_\bi_\br_\be_\bn_\bt _\b*_\b*_\b*_\bn_\ba_\bm_\be_\bl_\bi_\bs_\bt,
12 _\bi_\bn_\bt (_\b*_\bs_\be_\bl_\be_\bc_\bt)(_\bs_\bt_\br_\bu_\bc_\bt _\bd_\bi_\br_\be_\bn_\bt _\b*),
13 _\bi_\bn_\bt (_\b*_\bc_\bo_\bm_\bp_\ba_\br)(_\bc_\bo_\bn_\bs_\bt _\bv_\bo_\bi_\bd _\b*_\b, _\bc_\bo_\bn_\bs_\bt _\bv_\bo_\bi_\bd _\b*));
14
15 _\bi_\bn_\bt
16 a\bal\blp\bph\bha\bas\bso\bor\brt\bt(_\bc_\bo_\bn_\bs_\bt _\bv_\bo_\bi_\bd _\b*_\bd_\b1, _\bc_\bo_\bn_\bs_\bt _\bv_\bo_\bi_\bd _\b*_\bd_\b2);
17
18D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
19 The s\bsc\bca\ban\bnd\bdi\bir\br() function reads the directory _\bd_\bi_\br_\bn_\ba_\bm_\be 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 _\bn_\ba_\bm_\be_\bl_\bi_\bs_\bt.
23
24 The _\bs_\be_\bl_\be_\bc_\bt parameter is a pointer to a user supplied subroutine which is
25 called by s\bsc\bca\ban\bnd\bdi\bir\br() to select which entries are to be included in the ar-
26 ray. 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 _\bs_\be_\bl_\be_\bc_\bt is null, then all the directory entries will be
29 included.
30
31 The _\bc_\bo_\bm_\bp_\ba_\br 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 a\bal\blp\bph\bha\bas\bso\bor\brt\bt() function is a routine which can be used for the _\bc_\bo_\bm_\bp_\ba_\br
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
41D\bDI\bIA\bAG\bGN\bNO\bOS\bST\bTI\bIC\bCS\bS
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
45S\bSE\bEE\bE A\bAL\bLS\bSO\bO
46 directory(3), malloc(3), qsort(3), dir(5)
47
48H\bHI\bIS\bST\bTO\bOR\bRY\bY
49 The s\bsc\bca\ban\bnd\bdi\bir\br() and a\bal\blp\bph\bha\bas\bso\bor\brt\bt() functions appeared in 4.2BSD.
50
514.2 Berkeley Distribution June 4, 1993 1