aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-10-20 08:33:30 +0200
committerCharles <sircharlesaze@gmail.com>2019-10-20 08:33:30 +0200
commit1e754c1256dfe2380fa8933802ea9b4e5518be48 (patch)
tree5e32f09e58e2d17239c62a8c66836979c343d283
parent891dce09989e8ede692d4a6c23e7a208b09ca4d6 (diff)
downloadget_next_line-1e754c1256dfe2380fa8933802ea9b4e5518be48.tar.gz
get_next_line-1e754c1256dfe2380fa8933802ea9b4e5518be48.tar.bz2
get_next_line-1e754c1256dfe2380fa8933802ea9b4e5518be48.zip
Passed moulitest large_file test
-rw-r--r--.gitignore1
-rw-r--r--get_next_line.c7
-rw-r--r--get_next_line.h4
-rw-r--r--main.c7
4 files changed, 13 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 818f671..25bfce3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,5 +9,6 @@ testnl
test
test2
test3
+large_file.txt
*.dSYM
diff --git a/get_next_line.c b/get_next_line.c
index 0a5b001..47b85d2 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/20 07:39:13 by cacharle ### ########.fr */
+/* Updated: 2019/10/20 08:29:44 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -42,7 +42,8 @@ int get_next_line(int fd, char **line)
if (fd < 0 || line == NULL)
return (ERROR);
- had_rest = put_rest(line, rest);
+ if ((had_rest = put_rest(line, rest)) == -1)
+ return (LINE_READ);
while (rest[0] == '\0' && (ret = read(fd, buf, BUFFER_SIZE)) > 0)
{
buf[ret] = '\0';
@@ -74,6 +75,8 @@ int put_rest(char **line, char *rest)
rest[0] = '\0';
return (had_rest);
}
+ if (split_at + 1 == ft_strlen(rest))
+ had_rest = -1;
*line = malloc(sizeof(char) * (split_at + 1));
ft_strncpy(*line, rest, split_at);
(*line)[split_at] = '\0';
diff --git a/get_next_line.h b/get_next_line.h
index 15f9475..6a08080 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/20 07:39:00 by cacharle ### ########.fr */
+/* Updated: 2019/10/20 08:28:34 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,7 +14,7 @@
# define GET_NEXT_LINE_H
# ifndef BUFFER_SIZE
-# define BUFFER_SIZE 100
+# define BUFFER_SIZE 66
# endif
# define LINE_READ 1
diff --git a/main.c b/main.c
index 7ab241a..1c5baad 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/20 07:13:16 by cacharle ### ########.fr */
+/* Updated: 2019/10/20 08:30:07 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,6 +18,7 @@
int main(int argc, char **argv)
{
+ int i;
int fd;
char *line;
int ret;
@@ -29,10 +30,12 @@ int main(int argc, char **argv)
}
printf("BUFFER_SIZE = %d\n", BUFFER_SIZE);
fd = open(argv[1], O_RDONLY);
+ i = 1;
while ((ret = get_next_line(fd, &line)) == LINE_READ)
{
- printf("[%s]\n", line);
+ printf("%3d [%s]\n", i, line);
free(line);
+ i++;
}
if (ret == -1)
printf("error\n");