Browse Source

Use dynamically allocated buffer

master
Elouan MARTINET 4 years ago
parent
commit
19cb8a78aa
  1. 11
      get_next_line.c

11
get_next_line.c

@ -127,10 +127,10 @@ int get_next_line(const int fd, char **line)
{
static struct s_fd li[ULIMIT_N_42 + 2] = {{.fd = -1, .bf = 0, .n = 0}};
int i;
char bf[BUFF_SIZE];
char *bf;
int r;
if (!line || fd < 0 || fd == 1 || fd == 2)
if (!line || fd < 0 || fd == 1 || fd == 2 || !(bf = malloc(BUFF_SIZE)))
return (-1);
i = 0;
while (li[i].fd >= 0 && li[i].fd != fd)
@ -144,7 +144,8 @@ int get_next_line(const int fd, char **line)
r = ft_first_pass(li, i, bf, line);
else
r = ft_else_pass(li, i, line);
if (r != 42)
return (r);
return (ft_end_pass(li, i, bf, line));
if (r == 42)
r = ft_end_pass(li, i, bf, line);
free(bf);
return (r);
}

Loading…
Cancel
Save