From ca68aa1e6fca81213d19431439ad0b31863fe10c Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 22 Feb 2020 10:37:27 +0100 Subject: Added ft_putnbr_base{_fd}, ft_read_fd, ft_read_file --- src/io/ft_read_fd.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/io/ft_read_fd.c (limited to 'src/io/ft_read_fd.c') diff --git a/src/io/ft_read_fd.c b/src/io/ft_read_fd.c new file mode 100644 index 0000000..758216a --- /dev/null +++ b/src/io/ft_read_fd.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_read_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/22 10:26:44 by cacharle #+# #+# */ +/* Updated: 2020/02/22 10:36:26 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +#define FT_READ_FD_BUF_SIZE 2048 + +char *ft_read_fd(int fd) +{ + int ret; + char *file; + char buf[FT_READ_FD_BUF_SIZE + 1]; + + if ((file = ft_strdup("")) == NULL) + return (NULL); + while ((ret = read(fd, buf, FT_READ_FD_BUF_SIZE)) > 0) + { + buf[ret] = '\0'; + ft_strjoinf(file, buf, FT_STRJOINF_FST); + } + if (ret == -1) + { + free(file); + return (NULL); + } + return (file); +} -- cgit