1 2 3 4 5 6 7 8 9 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
|
void ft_fill_lst(t_list **lst, char *arg, char *root)
{
t_info *info;
char *tmp;
if (!ft_strequ(root, arg))
{
tmp = ft_strjoin(root, "/");
arg = ft_strjoin(tmp, arg);
}
info = (t_info *)malloc(sizeof(t_info));
lstat(arg, &info->buf)) == -1;
info->name = ft_strdup(arg);
ft_lstadd(lst, ft_lstnew(info, sizeof(t_info)));
}
void ft_isdir(t_list *lst, t_options option, int j)
{
DIR *dir;
t_list *list;
struct dirent * dirent;
while (lst)
{
if (((t_info *)(lst->content)) && (S_IFMT & ((t_info *)(lst->content))->buf.st_mode) == S_IFDIR)
{
if (!(dir = opendir(((t_info *)(lst->content))->name)))
perror(((t_info *)(lst->content))->name);
if (j > 1)
printf("\n\n%s:\n", ((t_info *)(lst->content))->name);
while ((dirent = readdir(dir)))
{
if (option.all == 1 || (dirent->d_name[0] != '.'))
{
ft_fill_lst(&((t_info *)(lst->content))->for_dir, dirent->d_name, ((t_info *)(lst->content))->name);
list = ((t_info *)(lst->content))->for_dir;
if (list && dirent->d_name[0] != '.' && option.recursive == 1 && S_ISDIR(((t_info *)(list->content))->buf.st_mode)) /* Cest ici que je segfault, quand jessaye d'acceder au content*/
ft_isdir(list, option, j);
}
}
closedir(dir);
}
lst = lst->next;
}
list = NULL;
} |
Partager