From c24fb630859217dbf8cce9f834fe1c4a058d17a0 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 11 Oct 2019 11:28:41 +0200 Subject: Moulitest passed except bonus tests - they updated the pdf, we can use `free`, fuck my life - think they check if i read BUFFER_SIZE, i dont, fuck my life - get reset --hard i guess --- get_next_line.c | 19 +++++++------------ get_next_line.h | 2 +- get_next_line_utils.c | 2 +- subject.en.pdf | Bin 1366391 -> 1308080 bytes 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/get_next_line.c b/get_next_line.c index d35516a..6098cec 100644 --- a/get_next_line.c +++ b/get_next_line.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/08 10:37:41 by cacharle #+# #+# */ -/* Updated: 2019/10/10 16:37:31 by cacharle ### ########.fr */ +/* Updated: 2019/10/11 11:21:32 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,23 +31,18 @@ int get_next_line(int fd, char **line) static int line_len = 0; static char rest_buf[BUFFER_SIZE + 1] = {0}; - if (line == NULL) + if (fd < 0 || line == NULL + || (ret = read_after(fd, local_buf, rest_buf)) == -1) return (ERROR); - local_buf[BUFFER_SIZE] = '\0'; - if ((ret = read_after(fd, local_buf, rest_buf)) <= 0 && local_buf[0] == 0) - return (ret); split_at = find_newline(local_buf); - if (split_at == -1 && ret < BUFFER_SIZE) - split_at = ft_strlen(local_buf); - if (split_at != -1) + if (split_at != -1 || ret == 0) { - ft_strncpy(rest_buf, local_buf + split_at + 1, - ft_strlen(local_buf) - split_at); if ((*line = malloc(sizeof(char) * (line_len + split_at + 1))) == NULL) return (ERROR); + ft_strncpy(rest_buf, local_buf + split_at + 1, + ft_strlen(local_buf) - split_at); ft_strncpy(*line + line_len, local_buf, split_at); - (*line)[line_len + split_at] = '\0'; - return (LINE_READ); + return (ret == 0 && local_buf[0] == 0 ? END_OF_FILE : LINE_READ); } line_len += BUFFER_SIZE; if ((ret = get_next_line(fd, line)) == -1) diff --git a/get_next_line.h b/get_next_line.h index 4059b05..650330f 100644 --- a/get_next_line.h +++ b/get_next_line.h @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/09 13:52:59 by cacharle #+# #+# */ -/* Updated: 2019/10/10 16:31:51 by cacharle ### ########.fr */ +/* Updated: 2019/10/11 11:22:20 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/get_next_line_utils.c b/get_next_line_utils.c index b80e327..8fbc78a 100644 --- a/get_next_line_utils.c +++ b/get_next_line_utils.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/08 08:52:59 by cacharle #+# #+# */ -/* Updated: 2019/10/10 16:39:08 by cacharle ### ########.fr */ +/* Updated: 2019/10/11 09:50:44 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/subject.en.pdf b/subject.en.pdf index da9882a..9f17646 100644 Binary files a/subject.en.pdf and b/subject.en.pdf differ -- cgit