Scan a directory
#include <dirent.h> int scandir( char * dirname, struct dirent ***namelist, int (*select)(const struct dirent *), int (*compar)(const void *,const void *) );
If select is NULL, all the directory entries are included.
You can use alphasort() as the compar parameter to sort the array alphabetically.
Use the -l c option to qcc to link against this library. This library is usually included automatically.
|This function is in libc.a, but not in libc.so (in order to save space).|
The scandir() function reads the directory dirname and builds an array of pointers to directory entries, using malloc() to allocate the space. The scandir() function returns the number of entries in the array, and stores a pointer to the array in the location referenced by namelist.
You can deallocate the memory allocated for the array by calling free(). Free each pointer in the array, and then free the array itself.
The number of entries in the array, or -1 if the directory can't be opened for reading, or malloc() can't allocate enough memory to hold all the data structures.
alphasort(), closedir(), dirent, free(), malloc(), opendir(), qsort(), readdir(), rewinddir(), seekdir(), telldir()