From: Dominik Kaiser Date: Fri, 22 Mar 2024 15:52:19 +0000 (+0100) Subject: It is working (or is it?) X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=c9e8005df3f0f3f68f58626420960519b078f5a4;p=42%2Fget_next_line.git 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...) --- 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