aboutsummaryrefslogtreecommitdiff
path: root/get_next_line.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-10-20 09:10:46 +0200
committerCharles <sircharlesaze@gmail.com>2019-10-20 09:10:46 +0200
commit9d66e3d084f575187b334d171a8bed40c476aa08 (patch)
tree0898c22e2224680cfcc83ab957573b7e38b2566d /get_next_line.c
parent1e754c1256dfe2380fa8933802ea9b4e5518be48 (diff)
downloadget_next_line-9d66e3d084f575187b334d171a8bed40c476aa08.tar.gz
get_next_line-9d66e3d084f575187b334d171a8bed40c476aa08.tar.bz2
get_next_line-9d66e3d084f575187b334d171a8bed40c476aa08.zip
Multiple fildes retarded version
Diffstat (limited to 'get_next_line.c')
-rw-r--r--get_next_line.c13
1 files changed, 7 insertions, 6 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);