| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* ft_get_file_content.c :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: bchanot <bchanot@student.42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2018/09/23 19:01:27 by bchanot #+# #+# */
- /* Updated: 2018/10/29 12:19:25 by bchanot ### ########.fr */
- /* */
- /* ************************************************************************** */
- #include "libft.h"
- #include <unistd.h>
- char *ft_get_file_content(int fd)
- {
- char *buff;
- char *tmp;
- char *s;
- buff = (char *)ft_memalloc(sizeof(char) * BUFF_SIZE + 1);
- ft_bzero(buff, BUFF_SIZE);
- s = NULL;
- while (read(fd, buff, BUFF_SIZE) > 0)
- {
- if (!s)
- s = ft_strdup(buff);
- else
- {
- tmp = ft_strjoin(s, buff);
- ft_memdel((void **)&s);
- s = tmp;
- tmp = NULL;
- }
- ft_bzero(buff, BUFF_SIZE);
- }
- ft_memdel((void **)&buff);
- return (s);
- }
|