aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--get_next_line.c22
-rw-r--r--get_next_line.h6
-rw-r--r--get_next_line_utils.c2
-rw-r--r--main.c2
4 files changed, 19 insertions, 13 deletions
diff --git a/get_next_line.c b/get_next_line.c
index 879dd0a..d09ab9e 100644
--- a/get_next_line.c
+++ b/get_next_line.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/19 09:08:36 by cacharle #+# #+# */
-/* Updated: 2019/10/24 10:55:30 by cacharle ### ########.fr */
+/* Updated: 2019/10/27 19:06:04 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -33,14 +33,13 @@
** return END_OF_FILE
*/
-int real_get_next_line(int fd, char **line, int ret, int split_at)
+int real_get_next_line(int fd, char **line, int ret)
{
+ int split_at;
t_bool had_rest;
char buf[BUFFER_SIZE + 1];
static char rest[OPEN_MAX][BUFFER_SIZE + 1] = {{0}};
- if (fd < 0 || fd > OPEN_MAX || line == NULL || BUFFER_SIZE < 0)
- return (ERROR);
if ((had_rest = put_rest(line, rest[fd])) == -1)
return (LINE_READ);
while (rest[fd][0] == '\0' && (ret = read(fd, buf, BUFFER_SIZE)) > 0)
@@ -58,17 +57,24 @@ int real_get_next_line(int fd, char **line, int ret, int split_at)
}
if (had_rest)
return (LINE_READ);
+ free(*line);
+ *line = NULL;
return (ret == -1 ? ERROR : END_OF_FILE);
}
int get_next_line(int fd, char **line)
{
- int ret;
- int split_at;
+ int ret;
- split_at = -1;
ret = 0;
- return (real_get_next_line(fd, line, ret, split_at));
+ if (fd < 0 || fd > OPEN_MAX || line == NULL || BUFFER_SIZE < 0)
+ return (ERROR);
+ if (BUFFER_SIZE == 0)
+ {
+ *line = NULL;
+ return (LINE_READ);
+ }
+ return (real_get_next_line(fd, line, ret));
}
int put_rest(char **line, char *rest)
diff --git a/get_next_line.h b/get_next_line.h
index f1f45aa..e556482 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/24 10:56:13 by cacharle ### ########.fr */
+/* Updated: 2019/10/27 19:10:23 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,7 +16,7 @@
# include <limits.h>
# ifndef BUFFER_SIZE
-# define BUFFER_SIZE 1
+# define BUFFER_SIZE 32
# endif
# define LINE_READ 1
@@ -32,7 +32,7 @@ typedef int t_bool;
** get_next_line.c
*/
-int real_get_next_line(int fd, char **line, int ret, int split_at);
+int real_get_next_line(int fd, char **line, int ret);
int get_next_line(int fd, char **line);
int put_rest(char **line, char *rest);
int find_newline(char *str);
diff --git a/get_next_line_utils.c b/get_next_line_utils.c
index 9bc96d9..61c8055 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/20 07:39:00 by cacharle ### ########.fr */
+/* Updated: 2019/10/27 19:02:57 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/main.c b/main.c
index 4fe5fa7..5da3734 100644
--- a/main.c
+++ b/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/10 09:27:41 by cacharle #+# #+# */
-/* Updated: 2019/10/24 10:56:42 by cacharle ### ########.fr */
+/* Updated: 2019/10/27 19:08:20 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */