fix bug on invalid fd

This commit is contained in:
Khaïs COLIN 2024-11-01 17:04:37 +01:00
parent b5a957f5a4
commit 25d6ee0ae9
3 changed files with 30 additions and 18 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/23 20:32:46 by kcolin #+# #+# */
/* Updated: 2024/11/01 13:26:41 by kcolin ### ########.fr */
/* Updated: 2024/11/01 17:02:27 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
@ -61,8 +61,10 @@ char *shorten_buffer(char *buffer)
/*
** returns 1 on error, 0 on success
*/
int setup_buffers(char **buffer, char **read_buffer)
int setup(char **buffer, char **read_buffer, int fd)
{
if (fd < 0)
return (1);
if (*buffer == NULL)
{
*buffer = malloc(1 * sizeof(char));
@ -116,7 +118,7 @@ char *get_next_line(int fd)
char *read_buffer;
int num_bytes_read;
if (setup_buffers(&buffer, &read_buffer) != 0)
if (setup(&buffer, &read_buffer, fd) != 0)
return (NULL);
num_bytes_read = 1;
while (num_bytes_read != 0)