This commit is contained in:
Tanguy MAZE 2019-03-19 14:47:33 +01:00
parent daeae8bb0f
commit 071672f7c1
2 changed files with 13 additions and 5 deletions

View File

@ -6,11 +6,12 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/07 15:12:59 by tmaze #+# #+# */
/* Updated: 2019/03/19 13:08:37 by tmaze ### ########.fr */
/* Updated: 2019/03/19 14:20:25 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdio.h>
static int get_last_ind(char *buff)
{
@ -51,6 +52,13 @@ static int flush_buff(char **line, char *buff)
return (i);
}
static void init_getline(char **line, int *check, int *ret)
{
*line = NULL;
*check = BUFF_SIZE;
*ret = -2;
}
int ft_getline(char **line)
{
static char buff[BUFF_SIZE] = "\0";
@ -60,8 +68,7 @@ int ft_getline(char **line)
if (line == NULL || BUFF_SIZE < 1)
return (-1);
*line = NULL;
check = BUFF_SIZE;
init_getline(line, &check, &ret);
while (check == BUFF_SIZE)
{
if (buff[0] == '\0')
@ -71,6 +78,7 @@ int ft_getline(char **line)
if (ret == 0 && *line == NULL)
return (0);
}
ft_printf("=== debug ===\nbuff: '%s'\nret: %d\n", buff, ret);
if ((i = flush_buff(line, buff)) == -1)
return (-1);
check = (buff[i] == '\0' && i != ret) ? BUFF_SIZE : i;

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/07 22:37:44 by tmaze #+# #+# */
/* Updated: 2019/01/13 17:44:21 by tmaze ### ########.fr */
/* Updated: 2019/03/19 14:33:02 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,5 +16,5 @@ void ft_putendl(char const *s)
{
if (s != NULL)
ft_putstr(s);
ft_putchar('\n');
write(0, "\n", 1);
}