02.07.2013 Views

A/UX® Programmer's Reference Sections

A/UX® Programmer's Reference Sections

A/UX® Programmer's Reference Sections

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

scandir(3) scandir(3)<br />

NAME<br />

scandi r - scan a directory<br />

SYNOPSIS<br />

iinclude <br />

iinclude <br />

scandir (dirname, namelist, select, compar)<br />

char *dirname;<br />

struct direct * (*namelist[] ) ;<br />

int (*select) () ;<br />

int (*compar) () ;<br />

alphasort(dl, d2)<br />

struct direct **dl, **d2;<br />

DESCRIPTION<br />

scandir reads the directory dirname and builds an array of<br />

pointers to directory entries using malloc(3). It returns the<br />

number of entries in the array and a pointer to the array through<br />

name list.<br />

The select parameter is a pointer to a user supplied subroutine<br />

which is called by scandir to select which entries are to be included<br />

in the array. The select routine is passed a pointer to a<br />

directory entry and should return a non-zero value if the directory<br />

entry is to be included in the array. If select is null, then all the<br />

directory entries will be included.<br />

The com par parameter is a pointer to a user supplied subroutine<br />

which is passed to qsort(3) to sort the completed array. If this<br />

pointer is null, the array is not sorted. alphasort is a routine<br />

which can be used for the compar parameter to sort the array alphabetically.<br />

The memory allocated for the array can be deallocated with free<br />

(see malloc(3» by freeing each pointer in the array and the array<br />

itself.<br />

RETURN VALUE<br />

Returns -1 if the directory cannot be opened for reading or if cannot<br />

allocate enough memory to hold all the data structures.<br />

SEE ALSO<br />

directory(3), malloc(3C), malloc(3X), qsort(3C),<br />

dir(4).<br />

I<br />

February, 1990<br />

RevisionC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!