From 999759e8dfee81cfa4cfd39380fa4ad02587ea99 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Thu, 2 Oct 2025 09:50:52 +0200 Subject: [PATCH] change glob to heap --- src/main.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main.c b/src/main.c index 95653e6..681aa0d 100644 --- a/src/main.c +++ b/src/main.c @@ -8,7 +8,7 @@ void rename_files(const char* dir_path, rename_func_ptr renamefunc) { - glob_t files; + glob_t* files = malloc(sizeof(glob_t)); struct stat statbuf; char* pattern = NULL; char* input_filename = NULL; @@ -22,14 +22,14 @@ void rename_files(const char* dir_path, rename_func_ptr renamefunc) memset(output_filename, 0, STR_MAX_LENGTH); sprintf(pattern, "%s/*", dir_path); - glob(pattern, 0, NULL, &files); + glob(pattern, 0, NULL, files); - for (int i = 0; i < files.gl_pathc; i++) { - stat(files.gl_pathv[i], &statbuf); - renamefunc(files.gl_pathv[i], output_filename); - if (strcmp(files.gl_pathv[i], output_filename) != 0) { - printf("%s -> %s\n", files.gl_pathv[i], output_filename); - rename(files.gl_pathv[i], output_filename); + for (int i = 0; i < files->gl_pathc; i++) { + stat(files->gl_pathv[i], &statbuf); + renamefunc(files->gl_pathv[i], output_filename); + if (strcmp(files->gl_pathv[i], output_filename) != 0) { + printf("%s -> %s\n", files->gl_pathv[i], output_filename); + rename(files->gl_pathv[i], output_filename); } if (S_ISDIR(statbuf.st_mode)) { @@ -41,7 +41,8 @@ void rename_files(const char* dir_path, rename_func_ptr renamefunc) memset(input_filename, 0, STR_MAX_LENGTH); } - globfree(&files); + globfree(files); + files = NULL; free(pattern); pattern = NULL; free(input_filename); -- 2.47.3