From 9d66e3d084f575187b334d171a8bed40c476aa08 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 20 Oct 2019 09:10:46 +0200 Subject: Multiple fildes retarded version --- get_next_line.c | 13 +++++++------ main.c | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/get_next_line.c b/get_next_line.c index 47b85d2..d5c4293 100644 --- a/get_next_line.c +++ b/get_next_line.c @@ -6,12 +6,13 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/19 09:08:36 by cacharle #+# #+# */ -/* Updated: 2019/10/20 08:29:44 by cacharle ### ########.fr */ +/* Updated: 2019/10/20 09:04:18 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include #include +#include #include "get_next_line.h" /* @@ -38,18 +39,18 @@ int get_next_line(int fd, char **line) int ret; int split_at; char buf[BUFFER_SIZE + 1]; - static char rest[BUFFER_SIZE + 1] = {0}; + static char rest[OPEN_MAX][BUFFER_SIZE + 1] = {{0}}; - if (fd < 0 || line == NULL) + if (fd < 0 || fd > OPEN_MAX || line == NULL) return (ERROR); - if ((had_rest = put_rest(line, rest)) == -1) + if ((had_rest = put_rest(line, rest[fd])) == -1) return (LINE_READ); - while (rest[0] == '\0' && (ret = read(fd, buf, BUFFER_SIZE)) > 0) + while (rest[fd][0] == '\0' && (ret = read(fd, buf, BUFFER_SIZE)) > 0) { buf[ret] = '\0'; if ((split_at = find_newline(buf)) != -1) { - ft_strncpy(rest, buf + split_at + 1, BUFFER_SIZE); + ft_strncpy(rest[fd], buf + split_at + 1, BUFFER_SIZE); buf[split_at] = '\0'; *line = ft_strappend(*line, buf); return (*line == NULL ? ERROR : LINE_READ); diff --git a/main.c b/main.c index 1c5baad..c29a2e2 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 08:30:07 by cacharle ### ########.fr */ +/* Updated: 2019/10/20 09:03:18 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ #include #include #include +#include #include "get_next_line.h" int main(int argc, char **argv) @@ -23,6 +24,7 @@ int main(int argc, char **argv) char *line; int ret; + /* printf("limit fdmax %d\n", OPEN_MAX); */ if (argc != 2) { printf("You forgot the filename"); -- cgit