BSD 4_3 release
[unix-history] / usr / man / man3 / scandir.3
CommitLineData
460316d1
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
95f51977 5.\" @(#)scandir.3 6.2 (Berkeley) 9/17/85
460316d1 6.\"
95f51977 7.TH SCANDIR 3 "September 17, 1985"
460316d1
KM
8.UC 5
9.SH NAME
7b21dbb4 10scandir, alphasort \- scan a directory
460316d1
KM
11.SH SYNOPSIS
12.nf
13.B #include <sys/types.h>
14.B #include <sys/dir.h>
15.PP
16.B scandir(dirname, namelist, select, compar)
17.B char *dirname;
18.B struct direct *(*namelist[]);
19.B int (*select)();
20.B int (*compar)();
21.PP
22.B alphasort(d1, d2)
23.B struct direct **d1, **d2;
24.fi
25.SH DESCRIPTION
26.I Scandir
27reads the directory
28.I dirname
29and builds an array of pointers to directory
30entries using
31.IR malloc (3).
32It returns the number of entries in the array and a pointer to the
33array through
34.IR namelist .
35.PP
36The
37.I select
38parameter is a pointer to a user supplied subroutine which is called by
39.I scandir
40to select which entries are to be included in the array.
41The select routine is passed a
42pointer to a directory entry and should return a non-zero
43value if the directory entry is to be included in the array.
44If
45.I select
46is null, then all the directory entries will be included.
47.PP
48The
49.I compar
50parameter is a pointer to a user supplied subroutine which is passed to
51.IR qsort (3)
52to sort the completed array. If this pointer is null, the array is not sorted.
53.I Alphasort
54is a routine which can be used for the
55.I compar
56parameter to sort the array alphabetically.
57.PP
58The memory allocated for the array can be deallocated with
59.I free
60(see
61.IR malloc (3))
62by freeing each pointer in the array and the array itself.
63.SH "SEE ALSO"
64directory(3),
65malloc(3),
66qsort(3),
67dir(5)
68.SH DIAGNOSTICS
69Returns \-1 if the directory cannot be opened for reading or if
70.IR malloc (3)
71cannot allocate enough memory to hold all the data structures.