forked from kyomawolf/minishell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line.c
42 lines (39 loc) · 1.39 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: jkasper <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/14 22:37:06 by jkasper #+# #+# */
/* Updated: 2022/03/19 15:29:53 by jkasper ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
char *get_next_line(int fd)
{
char *ret;
static char *str = NULL;
size_t i;
size_t ii;
ret = malloc(GNL_BUFFER + 1);
ret[0] = '\0';
i = 0;
ii = 0;
while (1)
{
if (str == NULL || str[i] == '\0')
{
if (get_filled(&str, fd) || !get_memory(&ret))
return (e_exit(&str, &ret));
if (str[0] == '\0')
return (s_exit(&str, &ret, i + 1, ii));
i = 0;
}
ret[ii] = str[i];
if (ret[ii] == '\n' || ret[ii] == '\0')
return (s_exit(&str, &ret, i + 1, ii));
i++;
ii++;
}
}