30static const char *matcher_type = NULL;
31static int (*matcher_filter) (
const char *file) = NULL;
33static int matcher(
const struct dirent *entry)
35 char *pos = strrchr(entry->d_name,
'.');
37 if (matcher_filter && !matcher_filter(entry->d_name))
42 if ((1 == strlen(entry->d_name) && entry->d_name[0] ==
'.') ||
43 (2 == strlen(entry->d_name) && !strcmp(entry->d_name,
"..")))
47 if (matcher_type[0] == 0)
54 return !strcmp(pos, matcher_type);
82int dir(
const char *
dir,
const char *type,
int (*filter) (
const char *file),
char ***list,
int strip)
86 struct dirent **namelist;
101 matcher_filter = filter;
102 n = scandir(
dir, &namelist, matcher, alphasort);
107 files = (
char **)malloc(n *
sizeof(
char *));
108 for (i = 0; i < n; i++) {
110 char *name = namelist[i]->d_name;
111 char *type = strrchr(name,
'.');
116 files[i] = strdup(name);
int dir(const char *dir, const char *type, int(*filter)(const char *file), char ***list, int strip)