From: Bastian Dehn Date: Thu, 2 Oct 2025 07:58:16 +0000 (+0200) Subject: change get files extra method X-Git-Tag: 1.1.1^2~6 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=6acd2dffe041197ee2424a5e120bf7db15b2b2dd;p=mv_none_space.git change get files extra method --- 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);