diff --git a/libft/src/get_next_line b/libft/src/get_next_line deleted file mode 160000 index 9f165f27..00000000 --- a/libft/src/get_next_line +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9f165f2770b6f768f232dde5d2ec09a3a5fabf35 diff --git a/libft/src/get_next_line/get_next_line.c b/libft/src/get_next_line/get_next_line.c new file mode 100644 index 00000000..29dd45ed --- /dev/null +++ b/libft/src/get_next_line/get_next_line.c @@ -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); +} diff --git a/libft/src/get_next_line/get_next_line.fr.pdf b/libft/src/get_next_line/get_next_line.fr.pdf new file mode 100644 index 00000000..03d33367 Binary files /dev/null and b/libft/src/get_next_line/get_next_line.fr.pdf differ