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;
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);
}
globfree(files);
files = NULL;
+ free(statbuf);
+ statbuf = NULL;
free(pattern);
pattern = NULL;
free(input_filename);