- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
DIR_STRUCT * fill_dir_struct(DIR_STRUCT * dir_stc, _ptr_by_val_(char *) base_dir_path, _ptr_by_val_(char *) offset_dir)
{
DIR_STRUCT * sub_dir;
DIR * srcdir;
struct stat st;
char full_sub_dir_path[MAX_PATH_SIZE];
struct dirent * dent;
sprintf(full_sub_dir_path, "%s/%s", base_dir_path, offset_dir);
dbgprintln("Directory %s", full_sub_dir_path);
if(NULL != (dir_stc = malloc(sizeof(DIR_STRUCT))))
{
memset(dir_stc, 0x00, sizeof(DIR_STRUCT));
if (NULL != (srcdir = opendir(full_sub_dir_path)))
{
if(NULL != (dir_stc->dir_path = malloc(strlen(offset_dir) + 1)))
{
strcpy(dir_stc->dir_path, offset_dir);
for( ;(NULL != (dent = readdir(srcdir))); )
{
if((0 != strcmp(dent->d_name, ".")) &&
(0 != strcmp(dent->d_name, "..")) &&
(0 <= fstatat(dirfd(srcdir), dent->d_name, &st, 0)))
{
if (S_ISDIR(st.st_mode)) //Directory
{
if(NULL != (sub_dir = fill_dir_struct(sub_dir, full_sub_dir_path, dent->d_name)))
{
dir_stc->sub_dirs = list_append_node(dir_stc->sub_dirs, sub_dir);
dir_stc->dir_files_size += sub_dir->dir_files_size;
dir_stc->sub_dir_files_count += sub_dir->sub_dir_files_count;
}
else
{
dir_stc = destroy_dir_struct(dir_stc);
break;
}
}
else //File
{
dbgprintln("File %s, size %lu bytes", dent->d_name, st.st_size);
dir_stc->dir_files = list_append_node(dir_stc->dir_files, allocate_and_copy_char_buffer(dent->d_name, strlen(dent->d_name) + 1));
dir_stc->dir_files_size += st.st_size;
dir_stc->sub_dir_files_count++;
}
}
}//End of for(;NULL != (dent = readdir(srcdir)); )
closedir(srcdir);
}
else//End of if(NULL != (dir_stc->dir_path = malloc(strlen(offset_dir) + 1)))
{
dir_stc = destroy_dir_struct(dir_stc);
}
}//End of if (NULL != (srcdir = opendir(full_sub_dir_path)))
else
{
dir_stc = destroy_dir_struct(dir_stc);
}
}//End of if(NULL != (dir_stc = malloc(sizeof(DIR_STRUCT))))
return dir_stc;
}
Восьмикратный индент, Йода нотейшн, const *(x) const в аргументах. Есть подозрение, что велосипедисты не знали о scandir.
Это кладезь говна.