Index of Section 3 Manual Pages
| Interix / SUA | scandir.3 | Interix / SUA |
scandir(3) scandir(3)
scandir()
NAME
scandir(), alphasort() - enumerate directory contents
SYNOPSIS
#include
#include
int scandir(const char *dirname, struct dirent ***namelist,
int (*select)(struct dirent *),
int (*compar)(const void *, const void *));
int alphasort(const void *d1, const void *d2);
DESCRIPTION
The scandir(3) function uses malloc(3)to allocate memory for an array,
fills that array with pointers to directory entries in the directory
identified by dirname, and then returns the number of entries in the
array. The namelist argument contains a pointer to the resulting array.
The scandir() function calls the user-supplied subroutine referenced by
the select argument to determine which entries are to be included in the
array. The scadir() function passes to the select routine a pointer to a
directory entry, and expects the select function to return a nonzero value
if the directory entry is to be included in the array. If the select
argument is null, all directory entries are included.
The compar argument points to a user-supplied subroutine that is passed to
qsort(3) to sort the completed array. If this pointer is null,the array is
not sorted.
The alphasort() function is a routine which can be used for the compar
argument to sort the array alphabetically.
The memory allocated for the array can be deallocated with free(3), by
freeing each pointer in the array and then the array itself.
RETURN VALUES
The scandir() function returns 0 on success, or -1 if the specified
directory canot be opened for reading or if sufficient memory to hold the
data structures cannot be allocated.
SEE ALSO
malloc(3)
qsort(3)
USAGE NOTES
The scandir function is thread safe. The alphasort function is not thread
safe.
None of these functions are async-signal safe.