diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | get_next_line.c | 14 | ||||
| -rw-r--r-- | get_next_line.h | 2 | ||||
| -rw-r--r-- | get_next_line_utils.c | 2 |
4 files changed, 14 insertions, 7 deletions
@@ -3,3 +3,6 @@ a.out get_next_line *.ghc test +test2 +test3 +*.dSYM diff --git a/get_next_line.c b/get_next_line.c index 9112ac7..d35516a 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 11:24:20 by cacharle ### ########.fr */ +/* Updated: 2019/10/10 16:37:31 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,10 +31,15 @@ int get_next_line(int fd, char **line) static int line_len = 0; static char rest_buf[BUFFER_SIZE + 1] = {0}; + if (line == NULL) + return (ERROR); local_buf[BUFFER_SIZE] = '\0'; if ((ret = read_after(fd, local_buf, rest_buf)) <= 0 && local_buf[0] == 0) return (ret); - if ((split_at = find_newline(local_buf)) != -1) + split_at = find_newline(local_buf); + if (split_at == -1 && ret < BUFFER_SIZE) + split_at = ft_strlen(local_buf); + if (split_at != -1) { ft_strncpy(rest_buf, local_buf + split_at + 1, ft_strlen(local_buf) - split_at); @@ -58,11 +63,10 @@ int read_after(int fd, char *local_buf, char *rest_buf) int ret; offset = ft_strlen(rest_buf); - ft_strncpy(local_buf, rest_buf, offset + 1); + ft_strncpy(local_buf, rest_buf, offset); rest_buf[0] = '\0'; if ((ret = read(fd, local_buf + offset, BUFFER_SIZE - offset)) == -1) return (ERROR); - if (ret == 0) - local_buf[offset + ret] = '\0'; + local_buf[offset + ret] = '\0'; return (ret); } diff --git a/get_next_line.h b/get_next_line.h index fb74ea3..4059b05 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 11:26:10 by cacharle ### ########.fr */ +/* Updated: 2019/10/10 16:31:51 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/get_next_line_utils.c b/get_next_line_utils.c index c48c62f..b80e327 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 09:29:53 by cacharle ### ########.fr */ +/* Updated: 2019/10/10 16:39:08 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ |
