diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-10-20 09:10:46 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-10-20 09:10:46 +0200 |
| commit | 9d66e3d084f575187b334d171a8bed40c476aa08 (patch) | |
| tree | 0898c22e2224680cfcc83ab957573b7e38b2566d | |
| parent | 1e754c1256dfe2380fa8933802ea9b4e5518be48 (diff) | |
| download | get_next_line-9d66e3d084f575187b334d171a8bed40c476aa08.tar.gz get_next_line-9d66e3d084f575187b334d171a8bed40c476aa08.tar.bz2 get_next_line-9d66e3d084f575187b334d171a8bed40c476aa08.zip | |
Multiple fildes retarded version
| -rw-r--r-- | get_next_line.c | 13 | ||||
| -rw-r--r-- | 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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <unistd.h> #include <stdlib.h> +#include <limits.h> #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); @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <stdio.h> #include <stdlib.h> #include <fcntl.h> +#include <limits.h> #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"); |
