]> gitweb.hhaalo.de Git - mv_none_space.git/commitdiff
change glob to heap
authorBastian Dehn <hhaalo@arcor.de>
Thu, 2 Oct 2025 07:50:52 +0000 (09:50 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 2 Oct 2025 07:50:52 +0000 (09:50 +0200)
src/main.c

index 95653e6cab5a7ceb4c5a246a10c2e4bd241288bc..681aa0d6080a233c5b693750d368b1a220938447 100644 (file)
@@ -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);