/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/15 13:55:54 by jhalford #+# #+# */ /* Updated: 2016/08/19 22:54:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #define BUF_SIZE 10 void ft_putstr(char *str) { while (*str) write(1, str++, 1); } int ft_error(int ac) { if (ac == 1) { ft_putstr("File name missing.\n"); return (1); } if (ac > 2) { ft_putstr("Too many arguments.\n"); return (1); } return (0); } int main(int ac, char **av) { int fd; int ret; char buf[BUF_SIZE + 1]; if (ft_error(ac)) return (0); fd = open(av[1], O_RDONLY); while ((ret = read(fd, buf, BUF_SIZE))) { buf[ret] = '\0'; write(1, buf, ret); } close(fd); return (0); }