get nextline no longer a module

This commit is contained in:
Jack Halford 2016-09-27 05:31:55 +02:00
parent c64fa4b786
commit 6e45d91e6b
3 changed files with 50 additions and 1 deletions

@ -1 +0,0 @@
Subproject commit 9f165f2770b6f768f232dde5d2ec09a3a5fabf35

View file

@ -0,0 +1,50 @@
#include "libft.h"
static char *ft_realloc(char *line, int size)
{
char *str;
str = (char *)malloc(sizeof(char) * (ft_strlen(line) + size + 1));
if (str == NULL)
return (NULL);
str = ft_strcpy(str, line);
free(line);
return (str);
}
int get_next_line(int const fd, char **line)
{
static char save[BUFF_SIZE] = "";
char buf[BUFF_SIZE + 1];
int ret;
char *pos;
*line = (char *)malloc(sizeof(char *) * (BUFF_SIZE + ft_strlen(save) + 1));
*line = ft_strcpy(*line, save);
if ((pos = ft_strchr(*line, '\n')))
{
/* printf("found \\n in save\n"); */
/* fflush(stdout); */
/* ft_putstr(save); */
ft_strcpy(save, pos + 1);
*pos = '\0';
return (1);
}
while ((ret = read(fd, buf, BUFF_SIZE)) > 0)
{
buf[ret] = '\0';
/* ft_putstr(buf); */
/* ft_putchar('/'); */
if ((pos = ft_strchr(buf, '\n')))
{
ft_strcpy(save, pos + 1);
*pos = '\0';
ft_strcat(*line, buf);
return (1);
}
if ((*line = ft_realloc(*line, ret)) == NULL)
return (-1);
ft_strcat(*line, buf);
}
return (0);
}

Binary file not shown.