1SCANDIR(3)                 Library Functions Manual                 SCANDIR(3)
2
3
4

NAME

6       scandir, alphasort - scan a directory
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/dir.h>
11
12       scandir(dirname, namelist, select, compar)
13       char *dirname;
14       struct direct *(*namelist[]);
15       int (*select)();
16       int (*compar)();
17
18       alphasort(d1, d2)
19       struct direct **d1, **d2;
20

DESCRIPTION

22       Scandir  reads the directory dirname and builds an array of pointers to
23       directory entries using malloc(3).  It returns the number of entries in
24       the array and a pointer to the array through namelist.
25
26       The  select  parameter is a pointer to a user supplied subroutine which
27       is called by scandir to select which entries are to be included in  the
28       array.  The select routine is passed a pointer to a directory entry and
29       should return a non-zero value if the directory entry is to be included
30       in  the  array.  If select is null, then all the directory entries will
31       be included.
32
33       The compar parameter is a pointer to a user supplied  subroutine  which
34       is  passed  to qsort(3) to sort the completed array. If this pointer is
35       null, the array is not sorted.  Alphasort is a  routine  which  can  be
36       used for the compar parameter to sort the array alphabetically.
37
38       The  memory  allocated  for the array can be deallocated with free (see
39       malloc(3)) by freeing each pointer in the array and the array itself.
40

SEE ALSO

42       directory(3), malloc(3), qsort(3), dir(5)
43

DIAGNOSTICS

45       Returns -1 if the directory cannot be opened for  reading  or  if  mal‐
46       loc(3) cannot allocate enough memory to hold all the data structures.
47
48
49
504.2 Berkeley Distribution     September 17, 1985                    SCANDIR(3)
Impressum