-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmino_reader.c
More file actions
59 lines (54 loc) · 1.61 KB
/
mino_reader.c
File metadata and controls
59 lines (54 loc) · 1.61 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mino_reader.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mschroed <mschroed@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/12/28 20:51:56 by mschroed #+# #+# */
/* Updated: 2019/01/06 21:13:57 by mschroed ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <libft.h>
t_mino *mino_cpy(int fd)
{
int ret;
char *buf;
t_mino *head;
buf = ft_strnew(21);
head = NULL;
while ((ret = read(fd, buf, 21)) == 21 && (buf[0] == '.' || buf[0] == '#'))
{
lst_append(&head, buf);
ft_strclr(buf);
}
if (ret == 20 && (buf[0] == '.' || buf[0] == '#'))
{
if (head == NULL)
head = fnew_mino(buf, 20);
else
lst_append(&head, buf);
}
if (ret != 20 || (buf[0] != '.' && buf[0] != '#'))
{
ft_strdel(&buf);
return (0);
}
ft_strdel(&buf);
return (head);
}
t_mino *mino_oc(char *file)
{
int fd;
t_mino *mino_lst;
if ((fd = open(file, O_RDONLY)) == -1)
return (0);
if ((mino_lst = mino_cpy(fd)) == 0)
{
close(fd);
return (0);
}
close(fd);
return (mino_lst);
}