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

index 681aa0d6080a233c5b693750d368b1a220938447..6a6d2c849d4f9e652c0d0a54f95d8ebbf320b310 100644 (file)
@@ -9,7 +9,7 @@
 void rename_files(const char* dir_path, rename_func_ptr renamefunc)
 {
        glob_t* files = malloc(sizeof(glob_t));
-       struct stat statbuf;
+       struct stat* statbuf = malloc(sizeof(struct stat));
        char* pattern = NULL;
        char* input_filename = NULL;
        char* output_filename = NULL;
@@ -25,14 +25,14 @@ void rename_files(const char* dir_path, rename_func_ptr renamefunc)
        glob(pattern, 0, NULL, files);
 
        for (int i = 0; i < files->gl_pathc; i++) {
-               stat(files->gl_pathv[i], &statbuf);
+               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)) {
+               if (S_ISDIR(statbuf->st_mode)) {
                        escape_str(output_filename, input_filename);
                        rename_files(input_filename, renamefunc);
                }
@@ -43,6 +43,8 @@ void rename_files(const char* dir_path, rename_func_ptr renamefunc)
 
        globfree(files);
        files = NULL;
+       free(statbuf);
+       statbuf = NULL;
        free(pattern);
        pattern = NULL;
        free(input_filename);