From: Luca Bacci Date: Thu, 29 Dec 2022 17:37:44 +0000 (+0100) Subject: Use babl utility to iterate over directory contents X-Git-Tag: archive/raspbian/1%0.1.106-3+rpi1^2~15^2^2~34 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=68f9a08ee41b24770222d755773c141470afa198;p=babl.git Use babl utility to iterate over directory contents --- diff --git a/babl/babl-extension.c b/babl/babl-extension.c index 8f06fcd..0d36eef 100644 --- a/babl/babl-extension.c +++ b/babl/babl-extension.c @@ -260,45 +260,53 @@ babl_extension_load (const char *path) } } +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) {