aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-10-11 11:28:41 +0200
committerCharles <sircharlesaze@gmail.com>2019-10-11 11:39:38 +0200
commitc24fb630859217dbf8cce9f834fe1c4a058d17a0 (patch)
tree2a44cac59db234326918495a5f3111f0f2989810
parent988090ac0de3cc7a57e3cd8dd76ffc43efd2fc46 (diff)
downloadget_next_line-recursion.tar.gz
get_next_line-recursion.tar.bz2
get_next_line-recursion.zip
Moulitest passed except bonus testsrecursion
- 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
-rw-r--r--get_next_line.c19
-rw-r--r--get_next_line.h2
-rw-r--r--get_next_line_utils.c2
-rw-r--r--subject.en.pdfbin1366391 -> 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 <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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
--- a/subject.en.pdf
+++ b/subject.en.pdf
Binary files differ