-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.c
96 lines (86 loc) · 2.18 KB
/
checker.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* checker.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ccharrie <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/11 16:32:00 by ccharrie #+# #+# */
/* Updated: 2018/01/04 12:07:41 by ccharrie ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
int ft_checkfile(char *params)
{
DIR *directory;
if (!(directory = opendir(params)))
return (0);
else
{
closedir(directory);
return (1);
}
}
int ft_checkopt(char *opt)
{
int i;
i = 0;
while (opt[i])
{
if (opt[i] == 'R' || opt[i] == 'r' || opt[i] == 't'
|| opt[i] == 'l' || opt[i] == 'a')
i++;
else
{
ft_putformat("ls: illegal option -- ", LIGHT_RED, NULL,
"BOLD UNDERLINE");
ft_putcformat(opt[i], LIGHT_RED, NULL, "BOLD UNDERLINE");
ft_putformat("\nusage: ls [-Ralrt] [file ...]\n", LIGHT_RED,
NULL, "BOLD UNDERLINE");
return (0);
}
}
return (1);
}
int ft_checklink2fold(char *str, DIR *directory, char *opt)
{
char *path;
char *link;
t_filein *file;
path = ft_openpath(str);
link = ft_thefile(str);
directory = opendir(path);
while ((file = readdir(directory)) != NULL)
{
if (ft_strcmp(link, file->d_name) == 0)
{
if (ft_strchr(opt, 'l') && file->d_type == DT_LNK)
{
closedir(directory);
return (1);
}
}
}
closedir(directory);
return (0);
}
void ft_delmy2dtab(char **tab)
{
int i;
i = 0;
while (tab[i])
{
free(tab[i]);
i++;
}
free(tab);
}
char **ft_deltabs(char **s1, char **s2, char **res, int i)
{
res = joindir(res, s2, i);
if (s1)
ft_delmy2dtab(s1);
if (s2)
ft_delmy2dtab(s2);
return (res);
}