From 6acd2dffe041197ee2424a5e120bf7db15b2b2dd Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Thu, 2 Oct 2025 09:58:16 +0200 Subject: [PATCH] change get files extra method --- src/main.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index 604c2d0..37bc8d3 100644 --- a/src/main.c +++ b/src/main.c @@ -6,19 +6,28 @@ #include "rename.h" #include "config.h" -void rename_files(const char* dir_path, rename_func_ptr renamefunc) +glob_t* get_files(const char* dir_path) { glob_t* files = malloc(sizeof(glob_t)); - struct stat* statbuf = malloc(sizeof(struct stat)); - char* pattern = malloc(sizeof(char) * strlen(dir_path) + 3); + + sprintf(pattern, "%s/*", dir_path); + glob(pattern, 0, NULL, files); + + free(pattern); + pattern = NULL; + return files; +} + +void rename_files(const char* dir_path, rename_func_ptr renamefunc) +{ + struct stat* statbuf = malloc(sizeof(struct stat)); char* input_filename = malloc(sizeof(char) * STR_MAX_LENGTH); memset(input_filename, 0, STR_MAX_LENGTH); char* output_filename = malloc(sizeof(char) * STR_MAX_LENGTH); memset(output_filename, 0, STR_MAX_LENGTH); - sprintf(pattern, "%s/*", dir_path); - glob(pattern, 0, NULL, files); + glob_t* files = get_files(dir_path); for (int i = 0; i < files->gl_pathc; i++) { stat(files->gl_pathv[i], statbuf); @@ -41,8 +50,6 @@ void rename_files(const char* dir_path, rename_func_ptr renamefunc) files = NULL; free(statbuf); statbuf = NULL; - free(pattern); - pattern = NULL; free(input_filename); input_filename = NULL; free(output_filename); -- 2.47.3