fd > 1024 fix

This commit is contained in:
Camille Chauvet 2022-11-23 15:28:59 +01:00
parent d612a3c927
commit 38ce8029e5

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/26 00:52:47 by cchauvet #+# #+# */
/* Updated: 2022/11/14 15:49:34 by cchauvet ### ########.fr */
/* Updated: 2022/11/23 15:19:15 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -76,29 +76,25 @@ char *ft_getextra(char *str)
char *get_next_line(int fd)
{
static char *stash[1024] = {};
static char *stash[1024] = {0};
char *buf1;
char *buf2;
if (fd > 1023)
return (NULL);
buf2 = stash[fd];
if (ft_strchr(stash[fd], '\n') == -1)
{
buf1 = ft_getline(fd);
buf2 = ft_strfjoin(stash[fd], buf1);
if (buf2 == NULL)
{
free(buf1);
return (NULL);
}
}
buf1 = ft_getreturn(buf2);
stash[fd] = ft_getextra(buf2);
free(buf2);
if (buf1 == NULL)
if (buf1 == NULL || buf2 == NULL)
{
free(stash[fd]);
free(buf1);
return (NULL);
}
free(buf2);
return (buf1);
}