-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line.c
39 lines (36 loc) · 1.37 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nfigueir <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/13 08:51:54 by nfigueir #+# #+# */
/* Updated: 2024/06/21 16:47:27 by nfigueir ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
char *get_next_line(int fd)
{
static t_data stash;
char line[7000000];
int i;
if (stash.is_init == 0)
ft_init_stash(&stash);
if (fd < 0 || fd >= MAX_FD || BUFFER_SIZE <= 0)
return (NULL);
i = 0;
while (1)
{
if (stash.buf_position >= stash.buf_size)
if (ft_read_buf(fd, &stash) <= 0)
break ;
line[i++] = stash.chr[stash.buf_position++];
if (line[i - 1] == '\n')
break ;
}
line[i] = '\0';
if (i == 0)
return (NULL);
return (ft_strdup(line));
}