remove some more lines again
This commit is contained in:
parent
48186c3719
commit
01da2291c8
1 changed files with 20 additions and 15 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/23 20:32:46 by kcolin #+# #+# */
|
/* Created: 2024/10/23 20:32:46 by kcolin #+# #+# */
|
||||||
/* Updated: 2024/11/01 12:41:32 by kcolin ### ########.fr */
|
/* Updated: 2024/11/01 13:17:01 by kcolin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -79,6 +79,24 @@ int setup_buffers(char **buffer, char **read_buffer)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *prepare_output_buffer(char **buffer, char *read_buffer)
|
||||||
|
{
|
||||||
|
char *outbuf;
|
||||||
|
|
||||||
|
outbuf = malloc((ft_strchr(*buffer, '\n') - *buffer + 2));
|
||||||
|
if (outbuf == NULL)
|
||||||
|
{
|
||||||
|
free(read_buffer);
|
||||||
|
free(*buffer);
|
||||||
|
*buffer = NULL;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
ft_strlcpy(outbuf, *buffer, ft_strchr(*buffer, '\n') - *buffer + 2);
|
||||||
|
*buffer = shorten_buffer(*buffer);
|
||||||
|
free(read_buffer);
|
||||||
|
return (outbuf);
|
||||||
|
}
|
||||||
|
|
||||||
char *get_next_line(int fd)
|
char *get_next_line(int fd)
|
||||||
{
|
{
|
||||||
static char *buffer = NULL;
|
static char *buffer = NULL;
|
||||||
|
|
@ -92,20 +110,7 @@ char *get_next_line(int fd)
|
||||||
while (num_bytes_read != 0)
|
while (num_bytes_read != 0)
|
||||||
{
|
{
|
||||||
if (ft_strchr(buffer, '\n'))
|
if (ft_strchr(buffer, '\n'))
|
||||||
{
|
return (prepare_output_buffer(&buffer, read_buffer));
|
||||||
outbuf = malloc((ft_strchr(buffer, '\n') - buffer + 2));
|
|
||||||
if (outbuf == NULL)
|
|
||||||
{
|
|
||||||
free(read_buffer);
|
|
||||||
free(buffer);
|
|
||||||
buffer = NULL;
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
ft_strlcpy(outbuf, buffer, ft_strchr(buffer, '\n') - buffer + 2);
|
|
||||||
buffer = shorten_buffer(buffer);
|
|
||||||
free(read_buffer);
|
|
||||||
return (outbuf);
|
|
||||||
}
|
|
||||||
num_bytes_read = read(fd, read_buffer, BUFFER_SIZE);
|
num_bytes_read = read(fd, read_buffer, BUFFER_SIZE);
|
||||||
if (num_bytes_read < 0)
|
if (num_bytes_read < 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue