diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-02-22 10:37:27 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-02-22 10:37:27 +0100 |
| commit | ca68aa1e6fca81213d19431439ad0b31863fe10c (patch) | |
| tree | f0a5b306f3ad62599cd67aba97d7dd154445dae5 /src/io/ft_read_file.c | |
| parent | 3c3f1115f6e9a9b914e2dcbd796501ca7ce85342 (diff) | |
| download | libft-ca68aa1e6fca81213d19431439ad0b31863fe10c.tar.gz libft-ca68aa1e6fca81213d19431439ad0b31863fe10c.tar.bz2 libft-ca68aa1e6fca81213d19431439ad0b31863fe10c.zip | |
Added ft_putnbr_base{_fd}, ft_read_fd, ft_read_file
Diffstat (limited to 'src/io/ft_read_file.c')
| -rw-r--r-- | src/io/ft_read_file.c | 33 |
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); +} |
