get nextline no longer a module
This commit is contained in:
parent
14d8f7c1b6
commit
96075b130d
3 changed files with 50 additions and 1 deletions
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 9f165f2770b6f768f232dde5d2ec09a3a5fabf35
|
|
||||||
50
libft/src/get_next_line/get_next_line.c
Normal file
50
libft/src/get_next_line/get_next_line.c
Normal 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);
|
||||||
|
}
|
||||||
BIN
libft/src/get_next_line/get_next_line.fr.pdf
Normal file
BIN
libft/src/get_next_line/get_next_line.fr.pdf
Normal file
Binary file not shown.
Loading…
Reference in a new issue