-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_opend.c
41 lines (38 loc) · 1.4 KB
/
ft_opend.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_opend.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ohachim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/22 15:52:55 by ohachim #+# #+# */
/* Updated: 2018/11/25 15:03:11 by magoumi ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
t_tet *ft_opend(int fd, int i)
{
t_tet *tets;
int ret;
char tet[BUFF_SIZE + 1];
tets = (t_tet *)malloc(sizeof(t_tet) * 26 + 1);
while ((ret = read(fd, tet, BUFF_SIZE)))
{
if (ret == -1)
return (0);
tet[ret] = '\0';
if (!ft_isvalid(tet))
return (0);
tets[i] = ft_tetr(tets[i], tet, i);
if (++i > 26)
return (0);
ret = read(fd, tet, 1);
tet[ret] = '\0';
if (tet[0] != '\n' && tet[0] != '\0')
return (0);
}
if (i == 0 || tet[0] == '\n')
return (0);
tets[i].l = '$';
return (tets);
}