ohshite(_("error closing configuration file '%.255s'"), fn);
}
+static int inv_alphasort(const void *a, const void *a) {
+ return -1 * strcoll((char*)a, (char*) b);
+}
+
void
loadfilters(void)
{
struct dirent *dent;
char *dirname = CONFIGDIR "/filters.d";
DIR *dir = opendir(dirname);
+ int names_len = 1024;
+ char **names = m_malloc(names_len * sizeof(char *));
+ int i = 0;
if (!dir) {
if (errno == ENOENT)
sprintf(file, "%s/%s", dirname, dent->d_name);
if (stat(file, &statbuf) != 0)
ohshite(_("error stating file '%s'"), file);
- if (S_ISREG(statbuf.st_mode))
- loadfilter(file);
+ if (S_ISREG(statbuf.st_mode)) {
+ names[i++] = m_strdup(dent->d_name);
+ if (i == names_len) {
+ names_len *= 2;
+ names = m_realloc(names,
+ names_len * sizeof (char *));
+ }
+ }
free(file);
}
+ qsort(names, i, sizeof(char *), inv_alphasort);
+ while (i > 0) {
+ loadfilter(names[--i]);
+ free(names[i]);
+ }
+ free(names);
closedir(dir);
}