-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_args.c
68 lines (60 loc) · 1.83 KB
/
check_args.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_args.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lpalacio <lpalacio@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/06 22:55:17 by lpalacio #+# #+# */
/* Updated: 2024/06/06 22:55:20 by lpalacio ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void error_out(int n)
{
write (1, "Fatal Error\n", 12);
write (1,"Terminating program\n",20);
exit(n);
}
t_list *read_map(char *argv)
{
int fd;
t_list *lst_map;
char *line;
fd = -1;
lst_map = NULL;
if (!argv)
error_out(1);
fd = open(argv, O_RDONLY);
if (fd < 0)
{
error_out(3);
}
line = get_next_line(fd);
if (line)
{
ft_lstadd_back(&lst_map, ft_lstnew(line));
line = get_next_line(fd);
while (line)
{
ft_lstadd_back(&lst_map, ft_lstnew(line));
line = get_next_line(fd);
}
}
close(fd);
return (lst_map);
}
char **check_args(char *argv)
{
t_list *lst_map;
t_list *lst;
lst_map = read_map(argv);
lst = lst_map;
while (lst)
{
printf ("%s\n", (char *)(lst)->content);
lst = (lst)->next;
}
ft_lstclear(&lst_map, free);
return (NULL);
}