-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_bonus.c
48 lines (43 loc) · 1.44 KB
/
get_next_line_bonus.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
43
44
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: haarab <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/27 12:59:40 by haarab #+# #+# */
/* Updated: 2022/12/28 21:08:08 by haarab ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
char *read_file(int fd, char *str)
{
char buff[BUFFER_SIZE + 1];
int red;
red = 1;
while (red != 0)
{
red = read (fd, buff, BUFFER_SIZE);
if (red == -1)
{
free(str);
return (NULL);
}
buff[red] = '\0';
str = ft_strjoin(str, buff);
if (check_new_line(str))
break ;
}
return (str);
}
char *get_next_line(int fd)
{
static char *str[OPEN_MAX];
char *ptr;
if (BUFFER_SIZE <= 0 || fd < 0)
return (NULL);
str[fd] = read_file(fd, str[fd]);
ptr = ft_get_line(str[fd]);
str[fd] = ft_cut(str[fd]);
return (ptr);
}