diff --git a/Makefile b/Makefile deleted file mode 100644 index 955dbc9..0000000 --- a/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -# **************************************************************************** # -# # -# ::: :::::::: # -# Makefile :+: :+: :+: # -# +:+ +:+ +:+ # -# By: adjoly +#+ +:+ +#+ # -# +#+#+#+#+#+ +#+ # -# Created: 2023/12/01 17:10:39 by adjoly #+# #+# # -# Updated: 2023/12/04 17:04:21 by adjoly ### ########.fr # -# # -# **************************************************************************** # - -NAME = get_next_line.a - -CC = clang - -SRCS = get_next_line.c \ - get_next_line_utils.c \ - -OBJS = $(SRCS:.c=.o) - -FLAGS = -Werror -Wall -Wextra - -HEADER = get_next_line.h - -$(NAME): $(OBJS) - $(CC) -o $@ $(SRCS) -g - -%.o: %.c - $(CC) $(FLAGS) -I $(HEADER) $< -c -o $@ -g - -all: $(NAME) - -clean: - rm -f $(OBJS) - -fclean: clean - rm -f $(NAME) - -re: fclean all - -.PHONY: clean all re fclean diff --git a/a.out b/a.out index 3f7617e..e311974 100755 Binary files a/a.out and b/a.out differ diff --git a/get_next_line.c b/get_next_line.c index 57a4242..dacc830 100644 --- a/get_next_line.c +++ b/get_next_line.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/01 17:11:59 by adjoly #+# #+# */ -/* Updated: 2023/12/06 11:18:18 by adjoly ### ########.fr */ +/* Updated: 2023/12/06 12:34:24 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,6 @@ char *get_next_line(int fd) { static char *buf; char *res; - char *tmp; int size; int bytes_read; @@ -37,37 +36,24 @@ char *get_next_line(int fd) res = ft_calloc(1, 1); if (!buf) buf = ft_calloc(sizeof(char), BUFFER_SIZE + 1); - while (1) + while (buf && res) { - tmp = ft_strjoin(res, buf); - if (!tmp) - return (NULL); - free(res); - res = tmp; - size = check_line(res); + // size = check_line(res); bytes_read = read(fd, buf, BUFFER_SIZE); - buf[bytes_read] = 0; - if (bytes_read == 0 && ft_strlen(res) != 0) + res = ft_strjoin(res, buf); + buf[bytes_read] = '\0'; + if (bytes_read < 1) { + if (ft_strlen(res) > 0) + return (res); free(buf); buf = NULL; - return (res); - } - else if (bytes_read == 0) return (NULL); - if (size != 0) - { - tmp = ft_strjoin(res, buf); - if (!tmp) - return (NULL); - free(res); - res = tmp; - ft_strlcpy(buf, &res[size], ft_strlen(&res[size])); - buf[ft_strlen(&res[size])] = 0; - res[size] = 0; - return (res); } + else if (bytes_read >= 1) + return (res); } + return (NULL); } #include diff --git a/get_next_line.h.gch b/get_next_line.h.gch deleted file mode 100644 index d5bd7b4..0000000 Binary files a/get_next_line.h.gch and /dev/null differ diff --git a/get_next_line_utils.c b/get_next_line_utils.c index fc7a29a..d84998c 100644 --- a/get_next_line_utils.c +++ b/get_next_line_utils.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/01 17:12:02 by adjoly #+# #+# */ -/* Updated: 2023/12/06 11:21:57 by adjoly ### ########.fr */ +/* Updated: 2023/12/06 12:05:08 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,6 +58,7 @@ char *ft_strjoin(char *s1, char *s2) i++; j++; } + free(s1); result[i] = '\0'; return (result); }