}
}
+struct dir_foreach_ctx
+{
+ const char **exclusion_patterns;
+};
+
static void
-babl_extension_load_dir (const char *base_path,
- const char **exclusion_patterns)
+dir_foreach (const char *base_path,
+ const char *entry,
+ void *user_data)
{
- DIR *dir;
+ struct dir_foreach_ctx *ctx = (struct dir_foreach_ctx*) user_data;
- if ((dir = opendir (base_path)))
+ if (entry[0] != '.')
{
- struct dirent *dentry;
+ char *path = NULL;
+ char *extension;
- while ((dentry = readdir (dir)) != NULL)
+ path = babl_strcat (path, base_path);
+ path = babl_strcat (path, BABL_DIR_SEPARATOR);
+ path = babl_strcat (path, entry);
+
+ if ((extension = strrchr (entry, '.')) != NULL &&
+ !strcmp (extension, SHREXT))
{
- if (dentry->d_name[0] != '.')
- {
- char *path = NULL;
- char *extension;
-
- path = babl_strcat (path, base_path);
- path = babl_strcat (path, BABL_DIR_SEPARATOR);
- path = babl_strcat (path, dentry->d_name);
-
- if ((extension = strrchr (dentry->d_name, '.')) != NULL &&
- !strcmp (extension, SHREXT))
- {
- int excluded = 0;
- for (int i = 0; exclusion_patterns[i]; i++)
- if (strstr (path, exclusion_patterns[i]))
- excluded = 1;
- if (!excluded)
- babl_extension_load (path);
- }
-
- babl_free (path);
- }
+ int excluded = 0;
+ for (int i = 0; ctx->exclusion_patterns[i]; i++)
+ if (strstr (path, ctx->exclusion_patterns[i]))
+ excluded = 1;
+ if (!excluded)
+ babl_extension_load (path);
}
- closedir (dir);
+
+ babl_free (path);
}
}
+static void
+babl_extension_load_dir (const char *base_path,
+ const char **exclusion_patterns)
+{
+ struct dir_foreach_ctx ctx;
+
+ ctx.exclusion_patterns = exclusion_patterns;
+
+ _babl_dir_foreach (base_path, dir_foreach, &ctx);
+}
+
static char *
expand_path (char *path)
{