Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ scandir(3) — A/UX 2.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

directory(3)

malloc(3C)

malloc(3X)

qsort(3C)

dir(4)




scandir(3) scandir(3)
NAME scandir - scan a directory SYNOPSIS #include <sys/types.h> #include <sys/dir.h> scandir(dirname, namelist, select, compar) char *dirname; struct direct *(*namelist[]); int (*select)(); int (*compar)(); alphasort(d1, d2) struct direct **d1, **d2; DESCRIPTION scandir reads the directory dirname and builds an array of pointers to directory entries using malloc(3). It returns the number of entries in the array and a pointer to the ar- ray through namelist. The select parameter is a pointer to a user supplied subrou- tine which is called by scandir to select which entries are to be included in the array. The select routine is passed a pointer to a directory entry and should return a non-zero value if the directory entry is to be included in the array. If select is null, then all the directory entries will be included. The compar parameter is a pointer to a user supplied subrou- tine which is passed to qsort(3) to sort the completed ar- ray. If this pointer is null, the array is not sorted. al- phasort is a routine which can be used for the compar param- eter to sort the array alphabetically. The memory allocated for the array can be deallocated with free (see malloc(3)) by freeing each pointer in the array and the array itself. RETURN VALUE Returns -1 if the directory cannot be opened for reading or if cannot allocate enough memory to hold all the data struc- tures. SEE ALSO directory(3), malloc(3C), malloc(3X), qsort(3C), dir(4). April, 1990 1

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026