fdf/libft/ft_read_file.c
2017-01-30 23:37:54 +02:00

31 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_read_file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/27 17:59:03 by gtertysh #+# #+# */
/* Updated: 2016/12/27 18:01:33 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *read_file(const int fd)
{
long readed;
long old_size;
char buf[BUF_S + 1];
char *string;
string = ft_memalloc(sizeof(char) * BUF_S);
while ((readed = read(fd, buf, BUF_S)))
{
buf[readed] = '\0';
old_size = ft_strlen(string);
string = ft_realloc(string, old_size + readed, old_size);
ft_strcat(string, buf);
}
return (string);
}