aboutsummaryrefslogtreecommitdiff
path: root/src/io/ft_read_fd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/io/ft_read_fd.c')
-rw-r--r--src/io/ft_read_fd.c36
1 files changed, 36 insertions, 0 deletions
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 <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* 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);
+}