-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_check.c
59 lines (52 loc) · 1.69 KB
/
ft_check.c
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
48
49
50
51
52
53
54
55
56
57
58
59
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaraval <tmaraval@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/07 10:52:26 by tmaraval #+# #+# */
/* Updated: 2018/01/04 14:26:32 by tmaraval ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void ft_check_error(t_opt *opt)
{
int i;
struct stat buf;
i = 0;
while (opt->dir[i])
{
if (ft_ls_isdir(opt->dir[i]) == FALSE
&& (lstat(opt->dir[i], &buf)) == -1)
{
ft_ls_perr(opt->dir[i]);
ft_delete_in_tab(opt->dir, i);
i--;
}
i++;
}
}
int ft_ls_isdir(char *path)
{
DIR *pdir;
if ((pdir = opendir(path)) == NULL)
return (FALSE);
closedir(pdir);
return (TRUE);
}
void ft_ls_firstcheck(t_opt *opt)
{
int i;
int originaldirnbr;
t_dirfile *last;
int deleteddirnbr;
last = NULL;
i = 0;
originaldirnbr = ft_get_dirnbr(opt->dir);
ft_sort_optdir(opt->dir, ft_get_dirnbr(opt->dir));
ft_check_error(opt);
deleteddirnbr = originaldirnbr - ft_get_dirnbr(opt->dir);
ft_sort_optdir(opt->dir, ft_get_dirnbr(opt->dir));
ft_print_optarg(opt, originaldirnbr, deleteddirnbr);
}