/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* read_file.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */ /* Updated: 2019/04/14 14:23:24 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ #include "../includes/fillit.h" char *read_file(char *file) { char buf[BUFFER_SIZE]; int fd; int rv; int i; char *result; if (((fd = open(file, O_RDONLY)) < 0) \ || ((rv = read(fd, &buf, BUFFER_SIZE)) < 0) \ || !(result = malloc(sizeof(char)))) return (NULL); buf[rv] = '\0'; i = 0; while (rv--) { result[i] = buf[i]; i++; } close(fd); return (result); }