cctools
|
Obtain a sorted directory listing. More...
Go to the source code of this file.
Functions | |
int | sort_dir (const char *dirname, char ***list, int(*sort)(const char *a, const char *b)) |
Obtain a sorted directory listing. | |
void | sort_dir_free (char **list) |
Free a sorted directory listing. | |
Obtain a sorted directory listing.
The prototype of sort_dir is a little scary, but it is easy to use. For example, to sort a given directory alphabetically:
char **list; int i; sort_dir(dirname,&list,strcmp); for(i=0;list[i];i++) printf("%s\n",list[i]); sort_dir_free(list);
int sort_dir | ( | const char * | dirname, |
char *** | list, | ||
int(* | sort )(const char *a, const char *b) ) |
Obtain a sorted directory listing.
dirname | The directory to list. |
list | A pointer to a doubly-indirect pointer, which will be filled with a list of strings. The final item will be null. This list must be freed with sort_dir_free. |
sort | A pointer to a function to compare two strings, which must have the same semantics as strcmp |
void sort_dir_free | ( | char ** | list | ) |
Free a sorted directory listing.
list | The list to be freed. |