diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-05-11 10:54:58 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-05-11 10:54:58 +0200 |
| commit | a4b9cda7d6733f2b077f8586e3b3e69351e7dfba (patch) | |
| tree | 74273a479519e22adb1c7afbee028c4341099369 /src/io | |
| parent | d3fb362c2e0b83cc9754a05ae5bc4a68a5f9269d (diff) | |
| download | libft-a4b9cda7d6733f2b077f8586e3b3e69351e7dfba.tar.gz libft-a4b9cda7d6733f2b077f8586e3b3e69351e7dfba.tar.bz2 libft-a4b9cda7d6733f2b077f8586e3b3e69351e7dfba.zip | |
Added ft_getfile
Diffstat (limited to 'src/io')
| -rw-r--r-- | src/io/ft_getfile.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/io/ft_getfile.c b/src/io/ft_getfile.c new file mode 100644 index 0000000..891ea51 --- /dev/null +++ b/src/io/ft_getfile.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_getfile.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/11 09:52:32 by charles #+# #+# */ +/* Updated: 2020/05/11 10:15:12 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_io.h" + +char *ft_getfile(int fd) +{ + char *s; + char buf[FT_GETFILE_BUFFER_SIZE + 1]; + int ret; + + if (fd < 0 || fd > OPEN_MAX) + return (NULL); + if ((s = ft_strdup("")) == NULL) + return (NULL); + while ((ret = read(fd, buf, FT_GETFILE_BUFFER_SIZE)) > 0) + { + buf[ret] = '\0'; + if ((s = ft_strjoinf(s, buf, FT_STRJOINF_FST)) == NULL) + return (NULL); + } + if (ret == -1) + { + free(s); + return (NULL); + } + return (s); +} |
