From 8445a8c9565930d5b7c3623656db4f71dd1c84f7 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 21 Dec 2025 00:18:11 +0100 Subject: [PATCH 01/10] style: Changing the strchr to strchr_index --- get_next_line.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/get_next_line.c b/get_next_line.c index b4c2928..a563dcc 100644 --- a/get_next_line.c +++ b/get_next_line.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/18 17:12:02 by rparodi #+# #+# */ -/* Updated: 2023/11/22 13:31:13 by rparodi ### ########.fr */ +/* Updated: 2025/12/20 23:59:09 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ char *ft_check(char *memory, int fd) buffer = (char *)malloc(sizeof(char) * (BUFFER_SIZE + 1)); if (!buffer) return (NULL); - while (ft_strchr(memory, '\n') <= 0 && bytescopy) + while (ft_strchr_index(memory, '\n') <= 0 && bytescopy) { bytescopy = read(fd, buffer, BUFFER_SIZE); if (bytescopy == -1) From 00f9484dc4072b93a8f9dd3ce639046f2270bccf Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 21 Dec 2025 00:18:31 +0100 Subject: [PATCH 02/10] feat: removing the file_converted --- get_next_line.c | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/get_next_line.c b/get_next_line.c index a563dcc..6f4a5f5 100644 --- a/get_next_line.c +++ b/get_next_line.c @@ -33,29 +33,6 @@ char *ft_check(char *memory, int fd) return (memory); } -char *file_converted(int fd) -{ - size_t i; - int read_bits; - char *str; - char c; - - i = 0; - c = 1; - read_bits = 1; - str = (char *)malloc(sizeof(char) * BUFFER_SIZE); - if (!str) - return (NULL); - while (read_bits != 0 && i < BUFFER_SIZE) - { - read_bits = read(fd, &c, 1); - str[i] = c; - i++; - } - str[i] = '\0'; - return (str); -} - char *ft_free(char *str) { free(str); From 4334807521e01062138a4e40185e92f7cc809476 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 21 Dec 2025 00:18:49 +0100 Subject: [PATCH 03/10] style: Changing the strchr to strchr_index --- get_next_line.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/get_next_line.h b/get_next_line.h index 3f76342..5d068d4 100644 --- a/get_next_line.h +++ b/get_next_line.h @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/18 17:12:04 by rparodi #+# #+# */ -/* Updated: 2023/11/23 18:15:34 by rparodi ### ########.fr */ +/* Updated: 2025/12/20 23:59:36 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ char *ft_get_line(char *str); char *get_next_line(int fd); -int ft_strchr(char *str, char c); +int ft_strchr_index(char *str, char c); char *ft_get_next(char *str); char *ft_get_line(char *str); char *ft_strjoin(char *s1, char *s2, int i, int j); From e166b486987ad55b8dcf354ebea07123ef013517 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 21 Dec 2025 00:19:00 +0100 Subject: [PATCH 04/10] feat: removing the file_converted --- get_next_line.h | 1 - 1 file changed, 1 deletion(-) diff --git a/get_next_line.h b/get_next_line.h index 5d068d4..7d4467d 100644 --- a/get_next_line.h +++ b/get_next_line.h @@ -26,7 +26,6 @@ char *ft_get_next(char *str); char *ft_get_line(char *str); char *ft_strjoin(char *s1, char *s2, int i, int j); size_t ft_strlen(char const *str); -char *file_converted(int fd); char *ft_free(char *str); char *ft_check(char *memory, int fd); From 9dd2216fa531d19bcc106ef1a247bcadcc5bf5d9 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 21 Dec 2025 00:19:07 +0100 Subject: [PATCH 05/10] style: Changing the strchr to strchr_index --- get_next_line_utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/get_next_line_utils.c b/get_next_line_utils.c index b4ad6c4..4e8615c 100644 --- a/get_next_line_utils.c +++ b/get_next_line_utils.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/18 17:14:47 by rparodi #+# #+# */ -/* Updated: 2023/11/22 13:35:03 by rparodi ### ########.fr */ +/* Updated: 2025/12/20 23:59:24 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -101,7 +101,7 @@ char *ft_get_next(char *str) return (temp); } -int ft_strchr(char *str, char c) +int ft_strchr_index(char *str, char c) { int i; From 50164d52adb53718858a48afe465e432adadf15f Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 21 Dec 2025 00:19:33 +0100 Subject: [PATCH 06/10] feat(bonus): adding the bonus sources --- get_next_line_bonus.c | 56 +++++++++++++++++ get_next_line_utils_bonus.c | 119 ++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 get_next_line_bonus.c create mode 100644 get_next_line_utils_bonus.c diff --git a/get_next_line_bonus.c b/get_next_line_bonus.c new file mode 100644 index 0000000..828d790 --- /dev/null +++ b/get_next_line_bonus.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/18 17:12:02 by rparodi #+# #+# */ +/* Updated: 2025/12/21 00:13:38 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "get_next_line.h" +#include + +char *ft_check(char *memory, int fd) +{ + char *buffer; + int bytescopy; + + bytescopy = 1; + buffer = (char *)malloc(sizeof(char) * (BUFFER_SIZE + 1)); + if (!buffer) + return (NULL); + while (ft_strchr_index(memory, '\n') <= 0 && bytescopy) + { + bytescopy = read(fd, buffer, BUFFER_SIZE); + if (bytescopy == -1) + return (ft_free(buffer)); + buffer[bytescopy] = '\0'; + memory = ft_strjoin(memory, buffer, 0, -1); + } + free(buffer); + return (memory); +} + +char *ft_free(char *str) +{ + free(str); + return (NULL); +} + +char *get_next_line(int fd) +{ + static char *memory[OPEN_MAX] = { 0 }; + char *line; + + if (fd < 0 || fd >= OPEN_MAX || BUFFER_SIZE <= 0) + return (NULL); + memory[fd] = ft_check(memory[fd], fd); + if (!memory[fd]) + return (ft_free(memory[fd])); + line = ft_get_line(memory[fd]); + memory[fd] = ft_get_next(memory[fd]); + return (line); +} diff --git a/get_next_line_utils_bonus.c b/get_next_line_utils_bonus.c new file mode 100644 index 0000000..4e8615c --- /dev/null +++ b/get_next_line_utils_bonus.c @@ -0,0 +1,119 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/18 17:14:47 by rparodi #+# #+# */ +/* Updated: 2025/12/20 23:59:24 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "get_next_line.h" + +size_t ft_strlen(char const *str) +{ + size_t i; + + i = 0; + if (str) + { + while (str[i]) + i++; + } + return (i); +} + +char *ft_strjoin(char *s1, char *s2, int i, int j) +{ + char *temp; + + if (!s1) + { + s1 = (char *)malloc(1); + s1[i] = '\0'; + } + if (!s2 || !s1) + return (NULL); + temp = (char *)malloc((ft_strlen(s1) + ft_strlen(s2) + 1)); + if (!temp) + return (NULL); + while (s1[i]) + { + temp[i] = s1[i]; + i++; + } + while (s2[++j]) + temp[i + j] = s2[j]; + temp[i + j] = '\0'; + free(s1); + return (temp); +} + +char *ft_get_line(char *str) +{ + char *temp; + int i; + + i = 0; + if (!str[i]) + return (NULL); + while (str[i] && str[i] != '\n') + i++; + temp = (char *)malloc((i + 2)); + if (!temp) + return (NULL); + i = 0; + while (str[i] && str[i] != '\n') + { + temp[i] = str[i]; + i++; + } + if (str[i] == '\n') + { + temp[i] = str[i]; + i++; + } + temp[i] = '\0'; + return (temp); +} + +char *ft_get_next(char *str) +{ + char *temp; + int i; + int j; + + i = 0; + while (str[i] && str[i] != '\n') + i++; + if (!str[i]) + return (ft_free(str)); + temp = (char *)malloc((ft_strlen(str) - i)); + if (!temp) + return (NULL); + j = i + 1; + while (str[++i]) + temp[i - j] = str[i]; + temp[i - j] = '\0'; + free(str); + return (temp); +} + +int ft_strchr_index(char *str, char c) +{ + int i; + + i = 0; + if (str) + { + while (str[i]) + { + if (str[i] == c) + return (i); + i++; + } + } + return (-1); +} From 250f632f6dac54843a7fcd3a9f15d7f6db940c6a Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 21 Dec 2025 00:19:46 +0100 Subject: [PATCH 07/10] feat(bonus): adding the bonus header --- get_next_line_bonus.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 get_next_line_bonus.h diff --git a/get_next_line_bonus.h b/get_next_line_bonus.h new file mode 100644 index 0000000..0bbdc56 --- /dev/null +++ b/get_next_line_bonus.h @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line_bonus.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/18 17:12:04 by rparodi #+# #+# */ +/* Updated: 2025/12/21 00:11:00 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef GET_NEXT_LINE_BONUS_H +# define GET_NEXT_LINE_BONUS_H +# ifndef BUFFER_SIZE +# define BUFFER_SIZE 420 +# endif + +# include +# include + +char *ft_get_line(char *str); +char *get_next_line(int fd); +int ft_strchr_index(char *str, char c); +char *ft_get_next(char *str); +char *ft_get_line(char *str); +char *ft_strjoin(char *s1, char *s2, int i, int j); +size_t ft_strlen(char const *str); +char *ft_free(char *str); +char *ft_check(char *memory, int fd); + +#endif From 20a44fbef37caf1a6401b99227e2865838fdd48d Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 29 Jan 2026 14:27:11 +0100 Subject: [PATCH 08/10] feat(gnl/bonus): adding open_max define --- get_next_line_bonus.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/get_next_line_bonus.h b/get_next_line_bonus.h index 0bbdc56..a149471 100644 --- a/get_next_line_bonus.h +++ b/get_next_line_bonus.h @@ -6,16 +6,21 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/18 17:12:04 by rparodi #+# #+# */ -/* Updated: 2025/12/21 00:11:00 by rparodi ### ########.fr */ +/* Updated: 2026/01/29 14:24:48 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef GET_NEXT_LINE_BONUS_H # define GET_NEXT_LINE_BONUS_H + # ifndef BUFFER_SIZE # define BUFFER_SIZE 420 # endif +# ifndef OPEN_MAX +# define OPEN_MAX 1024 +# endif + # include # include From c2f5d7e592a96b194545d16342aab88d22dc9f6d Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 29 Jan 2026 14:27:28 +0100 Subject: [PATCH 09/10] feat(bonus): replacing mandatory header by bonus header --- get_next_line_utils_bonus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/get_next_line_utils_bonus.c b/get_next_line_utils_bonus.c index 4e8615c..33d34a8 100644 --- a/get_next_line_utils_bonus.c +++ b/get_next_line_utils_bonus.c @@ -1,16 +1,16 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* get_next_line_utils.c :+: :+: :+: */ +/* get_next_line_utils_bonus.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/18 17:14:47 by rparodi #+# #+# */ -/* Updated: 2025/12/20 23:59:24 by rparodi ### ########.fr */ +/* Updated: 2026/01/29 14:26:18 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ -#include "get_next_line.h" +#include "get_next_line_bonus.h" size_t ft_strlen(char const *str) { From ee27ca6db6db85d7c5129a8823495d10510b4245 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 29 Jan 2026 14:28:00 +0100 Subject: [PATCH 10/10] feat(bonus): replacing mandatory header by bonus header --- get_next_line_bonus.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/get_next_line_bonus.c b/get_next_line_bonus.c index 828d790..3b0a7f9 100644 --- a/get_next_line_bonus.c +++ b/get_next_line_bonus.c @@ -6,12 +6,11 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/18 17:12:02 by rparodi #+# #+# */ -/* Updated: 2025/12/21 00:13:38 by rparodi ### ########.fr */ +/* Updated: 2026/01/29 14:25:47 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ -#include "get_next_line.h" -#include +#include "get_next_line_bonus.h" char *ft_check(char *memory, int fd) {