Commit | Line | Data |
---|---|---|
460316d1 | 1 | .\" Copyright (c) 1983 Regents of the University of California. |
25aac6e1 | 2 | .\" All rights reserved. |
460316d1 | 3 | .\" |
91cff1e1 | 4 | .\" %sccs.include.redist.man% |
25aac6e1 | 5 | .\" |
955256c9 | 6 | .\" @(#)scandir.3 6.7 (Berkeley) %G% |
460316d1 | 7 | .\" |
de30fdda | 8 | .TH SCANDIR 3 "" |
460316d1 KM |
9 | .UC 5 |
10 | .SH NAME | |
7b21dbb4 | 11 | scandir, alphasort \- scan a directory |
460316d1 KM |
12 | .SH SYNOPSIS |
13 | .nf | |
643c10cf KB |
14 | .ft B |
15 | #include <sys/types.h> | |
16 | #include <dirent.h> | |
17 | ||
18 | scandir(dirname, namelist, select, compar) | |
19 | char *dirname; | |
955256c9 | 20 | struct dirent ***namelist; |
643c10cf KB |
21 | int (*select)(); |
22 | int (*compar)(); | |
23 | ||
24 | alphasort(d1, d2) | |
25 | void *d1, *d2; | |
26 | .ft R | |
460316d1 KM |
27 | .fi |
28 | .SH DESCRIPTION | |
29 | .I Scandir | |
30 | reads the directory | |
31 | .I dirname | |
32 | and builds an array of pointers to directory | |
33 | entries using | |
34 | .IR malloc (3). | |
4754ea9c KB |
35 | It returns the number of entries in the array. |
36 | A pointer to the array of directory entries is stored in the location | |
37 | referenced by | |
460316d1 KM |
38 | .IR namelist . |
39 | .PP | |
40 | The | |
41 | .I select | |
42 | parameter is a pointer to a user supplied subroutine which is called by | |
43 | .I scandir | |
44 | to select which entries are to be included in the array. | |
45 | The select routine is passed a | |
46 | pointer to a directory entry and should return a non-zero | |
47 | value if the directory entry is to be included in the array. | |
48 | If | |
49 | .I select | |
50 | is null, then all the directory entries will be included. | |
51 | .PP | |
52 | The | |
53 | .I compar | |
54 | parameter is a pointer to a user supplied subroutine which is passed to | |
55 | .IR qsort (3) | |
643c10cf KB |
56 | to sort the completed array. |
57 | If this pointer is null, the array is not sorted. | |
58 | .PP | |
460316d1 KM |
59 | .I Alphasort |
60 | is a routine which can be used for the | |
61 | .I compar | |
62 | parameter to sort the array alphabetically. | |
63 | .PP | |
64 | The memory allocated for the array can be deallocated with | |
643c10cf KB |
65 | .IR free (3), |
66 | by freeing each pointer in the array and then the array itself. | |
460316d1 | 67 | .SH "SEE ALSO" |
643c10cf | 68 | directory(3), malloc(3), qsort(3), dir(5) |
460316d1 KM |
69 | .SH DIAGNOSTICS |
70 | Returns \-1 if the directory cannot be opened for reading or if | |
71 | .IR malloc (3) | |
72 | cannot allocate enough memory to hold all the data structures. |