From 1e754c1256dfe2380fa8933802ea9b4e5518be48 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 20 Oct 2019 08:33:30 +0200 Subject: Passed moulitest large_file test --- .gitignore | 1 + get_next_line.c | 7 +++++-- get_next_line.h | 4 ++-- main.c | 7 +++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 818f671..25bfce3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,6 @@ testnl test test2 test3 +large_file.txt *.dSYM diff --git a/get_next_line.c b/get_next_line.c index 0a5b001..47b85d2 100644 --- a/get_next_line.c +++ b/get_next_line.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/19 09:08:36 by cacharle #+# #+# */ -/* Updated: 2019/10/20 07:39:13 by cacharle ### ########.fr */ +/* Updated: 2019/10/20 08:29:44 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,7 +42,8 @@ int get_next_line(int fd, char **line) if (fd < 0 || line == NULL) return (ERROR); - had_rest = put_rest(line, rest); + if ((had_rest = put_rest(line, rest)) == -1) + return (LINE_READ); while (rest[0] == '\0' && (ret = read(fd, buf, BUFFER_SIZE)) > 0) { buf[ret] = '\0'; @@ -74,6 +75,8 @@ int put_rest(char **line, char *rest) rest[0] = '\0'; return (had_rest); } + if (split_at + 1 == ft_strlen(rest)) + had_rest = -1; *line = malloc(sizeof(char) * (split_at + 1)); ft_strncpy(*line, rest, split_at); (*line)[split_at] = '\0'; diff --git a/get_next_line.h b/get_next_line.h index 15f9475..6a08080 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/20 07:39:00 by cacharle ### ########.fr */ +/* Updated: 2019/10/20 08:28:34 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ # define GET_NEXT_LINE_H # ifndef BUFFER_SIZE -# define BUFFER_SIZE 100 +# define BUFFER_SIZE 66 # endif # define LINE_READ 1 diff --git a/main.c b/main.c index 7ab241a..1c5baad 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/10 09:27:41 by cacharle #+# #+# */ -/* Updated: 2019/10/20 07:13:16 by cacharle ### ########.fr */ +/* Updated: 2019/10/20 08:30:07 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,7 @@ int main(int argc, char **argv) { + int i; int fd; char *line; int ret; @@ -29,10 +30,12 @@ int main(int argc, char **argv) } printf("BUFFER_SIZE = %d\n", BUFFER_SIZE); fd = open(argv[1], O_RDONLY); + i = 1; while ((ret = get_next_line(fd, &line)) == LINE_READ) { - printf("[%s]\n", line); + printf("%3d [%s]\n", i, line); free(line); + i++; } if (ret == -1) printf("error\n"); -- cgit