cctools
|
Obtain a sorted directory listing. More...
Go to the source code of this file.
Macros | |
#define | sort_dir_free free |
Free a sorted directory listing. More... | |
Functions | |
int | sort_dir (const char *dirname, char ***list, int(*sort)(const char *a, const char *b)) |
Obtain a sorted directory listing. More... | |
Obtain a sorted directory listing.
The prototype of @ref 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);
#define sort_dir_free free |
Free a sorted directory listing.
list | The list to be freed. |
int sort_dir | ( | const char * | dirname, |
char *** | list, | ||
int(*)(const char *a, const char *b) | sort | ||
) |
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 |