aboutsummaryrefslogtreecommitdiff
path: root/src/io/ft_read_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/io/ft_read_file.c')
-rw-r--r--src/io/ft_read_file.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/io/ft_read_file.c b/src/io/ft_read_file.c
new file mode 100644
index 0000000..90ee38d
--- /dev/null
+++ b/src/io/ft_read_file.c
@@ -0,0 +1,33 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_read_file.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/22 10:32:47 by cacharle #+# #+# */
+/* Updated: 2020/02/22 10:35:07 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_io.h"
+
+char *ft_read_file(char *filename)
+{
+ int fd;
+ char *file;
+
+ if ((fd = open(filename, O_RDONLY)) < 0 || fd > OPEN_MAX)
+ return (NULL);
+ if ((file = ft_read_fd(fd)) == NULL)
+ {
+ free(file);
+ return (NULL);
+ }
+ if (close(fd) < 0)
+ {
+ free(file);
+ return (NULL);
+ }
+ return (file);
+}