]> gitweb.hhaalo.de Git - mv_none_space.git/commitdiff
return glob file on stack
authorBastian Dehn <hhaalo@arcor.de>
Wed, 4 Mar 2026 19:20:48 +0000 (20:20 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Wed, 4 Mar 2026 19:20:48 +0000 (20:20 +0100)
src/main.c

index 11f85736364f7088b420982ba2150a5e1c6cfeb9..46976a994ebf282f2893084235f9d7bf1782ddca 100644 (file)
@@ -7,13 +7,13 @@
 #include "rename.h"
 #include "config.h"
 
-glob_t* get_files(const char* dir_path)
+glob_t get_files(const char* dir_path)
 {
-       glob_t* files = malloc(sizeof(glob_t));
+       glob_t files;
        char* pattern = malloc(sizeof(char) * strlen(dir_path) + 3);
 
        sprintf(pattern, "%s/*", dir_path);
-       glob(pattern, 0, NULL, files);
+       glob(pattern, 0, NULL, &files);
 
        free(pattern);
        pattern = NULL;
@@ -41,11 +41,11 @@ void rename_file(const char* input, const char* output)
 
 void rename_files(const char* dir_path, rename_ptr renamefunc)
 {
-       glob_t* files = get_files(dir_path);
-       for (size_t i = 0; i < files->gl_pathc; i++) {
-               char* output = strdup(files->gl_pathv[i]);
+       glob_t files = get_files(dir_path);
+       for (size_t i = 0; i < files.gl_pathc; i++) {
+               char* output = strdup(files.gl_pathv[i]);
                output = renamefunc(&output);
-               rename_file(files->gl_pathv[i], output);
+               rename_file(files.gl_pathv[i], output);
 
                if (is_dir(output)) {
                        output = escape(&output);
@@ -56,9 +56,7 @@ void rename_files(const char* dir_path, rename_ptr renamefunc)
                output = NULL;
        }
 
-       globfree(files);
-       free(files);
-       files = NULL;
+       globfree(&files);
 }
 
 int main(int argc, char* argv[])