]> gitweb.hhaalo.de Git - mv_none_space.git/commitdiff
change get files extra method
authorBastian Dehn <hhaalo@arcor.de>
Thu, 2 Oct 2025 07:58:16 +0000 (09:58 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 2 Oct 2025 07:58:16 +0000 (09:58 +0200)
src/main.c

index 604c2d0ecdbb2b600240d70e0bf874026ec2fa85..37bc8d308504c53f00e67f37d41703d43265172f 100644 (file)
@@ -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);