-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line.c
37 lines (34 loc) · 1.35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mpedroso <mpedroso@student.42lisboa.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/17 11:55:01 by mpedroso #+# #+# */
/* Updated: 2022/11/29 15:29:57 by mpedroso ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
char *get_next_line(int fd)
{
static char line[BUFFER_SIZE + 1];
char *gnl;
int i;
if (fd < 0 || BUFFER_SIZE < 1 || FOPEN_MAX < fd)
return (NULL);
gnl = ft_strjoin(0, line);
if (clear_ln(line))
return (gnl);
i = read(fd, line, BUFFER_SIZE);
if (i < 0 || (i == 0 && (*gnl == '\0')))
return (free_gnl(gnl));
while (i > 0)
{
gnl = ft_strjoin(gnl, line);
if (clear_ln(line))
break ;
i = read(fd, line, BUFFER_SIZE);
}
return (gnl);
}