-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line.c
42 lines (39 loc) · 1.53 KB
/
get_next_line.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: msubtil- <msubtil-@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/21 21:28:54 by msubtil- #+# #+# */
/* Updated: 2022/06/27 21:42:20 by msubtil- ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
char *get_next_line(int fd)
{
static t_file fdata;
t_list *outlst;
size_t bytes;
size_t total_bytes;
outlst = NULLPTR;
if (read(fd, fdata.buf, 0) != 0)
return (NULLPTR);
total_bytes = parse_for_newline(&fdata);
allocate_and_cpy(&outlst, total_bytes, &fdata);
while (fdata.newline_flg == FALSE)
{
fdata.read_bytes = read(fd, fdata.buf, BUFFER_SIZE);
fdata.idx = 0;
if (fdata.read_bytes == 0)
break ;
bytes = 1;
while (fdata.newline_flg == FALSE && bytes > 0)
{
bytes = parse_for_newline(&fdata);
total_bytes += bytes;
allocate_and_cpy(&outlst, bytes, &fdata);
}
}
return (lstjoin(outlst, total_bytes));
}