remove some more lines

This commit is contained in:
Khaïs COLIN 2024-11-01 12:43:01 +01:00
parent 330db7596a
commit 48186c3719

View file

@ -6,7 +6,7 @@
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/23 20:32:46 by kcolin #+# #+# */
/* Updated: 2024/11/01 12:34:14 by kcolin ### ########.fr */
/* Updated: 2024/11/01 12:41:32 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
@ -58,6 +58,27 @@ char *shorten_buffer(char *buffer)
return (outbuf);
}
/*
** returns 1 on error, 0 on success
*/
int setup_buffers(char **buffer, char **read_buffer)
{
if (*buffer == NULL)
{
*buffer = malloc(1 * sizeof(char));
if (*buffer == NULL)
return (1);
*buffer[0] = '\0';
}
*read_buffer = malloc((BUFFER_SIZE + 1) * sizeof(char));
if (*read_buffer == NULL)
{
free(*buffer);
return (1);
}
return (0);
}
char *get_next_line(int fd)
{
static char *buffer = NULL;
@ -65,19 +86,8 @@ char *get_next_line(int fd)
int num_bytes_read;
char *outbuf;
if (buffer == NULL)
{
buffer = malloc(1 * sizeof(char));
if (buffer == NULL)
return (NULL);
buffer[0] = '\0';
}
read_buffer = malloc((BUFFER_SIZE + 1) * sizeof(char));
if (read_buffer == NULL)
{
free(buffer);
if (setup_buffers(&buffer, &read_buffer) != 0)
return (NULL);
}
num_bytes_read = 1;
while (num_bytes_read != 0)
{