-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_next_line.c
More file actions
38 lines (35 loc) · 1.29 KB
/
Copy pathget_next_line.c
File metadata and controls
38 lines (35 loc) · 1.29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahajji <ahajji@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/25 11:37:22 by ahajji #+# #+# */
/* Updated: 2022/10/30 16:01:40 by ahajji ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
char *get_next_line(int fd)
{
char buf[BUFFER_SIZE + 1];
static char *con;
char *ptr;
int r;
r = 1;
ptr = 0;
if (con != NULL)
ptr = ft_strjoin(con, ptr);
while (r > 0)
{
r = read(fd, buf, BUFFER_SIZE);
if (r < 0 || fd == 1 || fd == 2)
break ;
buf[r] = '\0';
ptr = ft_strjoin(ptr, buf);
if (new_line(ptr))
break ;
}
con = get_last_line(ptr);
return (_get_line(ptr));
}