From c9e8005df3f0f3f68f58626420960519b078f5a4 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Fri, 22 Mar 2024 16:52:19 +0100 Subject: [PATCH] It is working (or is it?) If '\n' is the last character in the buffer it won't work. Other than that everything is working fine (as far as my current tests go...) --- get_next_line.c | 94 ++++++++++++++++++++++++++++++++----------- get_next_line.h | 6 ++- get_next_line_utils.c | 12 +++++- 3 files changed, 86 insertions(+), 26 deletions(-) diff --git a/get_next_line.c b/get_next_line.c index 2f5a954..7b43e06 100644 --- a/get_next_line.c +++ b/get_next_line.c @@ -6,48 +6,96 @@ /* By: dkaiser 0) + get_next_line_rec(fd, buf, &result, 0); + } + *ptr_result = result; } char *get_next_line(int fd) { - static char buffer[BUFFER_SIZE]; + static char buf[BUFFER_SIZE]; + int i; char *result; + int readlen; - return (NULL); + i = 0; + readlen = 0; result = NULL; - result = get_next_line_rec(fd, buffer, result); + while (i < BUFFER_SIZE && !buf[i]) + i++; + if (i == BUFFER_SIZE) + { + readlen = read(fd, buf, BUFFER_SIZE); + if (readlen > 0) + return (get_next_line(fd)); + return (NULL); + } + get_next_line_rec(fd, buf, &result, i); return (result); } diff --git a/get_next_line.h b/get_next_line.h index 1e9a6f6..f0b0006 100644 --- a/get_next_line.h +++ b/get_next_line.h @@ -6,7 +6,7 @@ /* By: dkaiser