/* ************************************************************************** */ /* LE - / */ /* / */ /* ft_dprintf.c .:: .:/ . .:: */ /* +:+:+ +: +: +:+:+ */ /* By: rbousset +:+ +: +: +:+ */ /* #+# #+ #+ #+# */ /* Created: 2020/01/17 14:38:00 by rbousset #+# ## ## #+# */ /* Updated: 2020/01/17 14:38:01 by rbousset ### #+. /#+ ###.fr */ /* / */ /* / */ /* ************************************************************************** */ #include #include #include #include #include static int ft_printf_return(int fd, t_printflist *pflist) { int ret; ret = write(fd, pflist->output, pflist->fulllen); ft_memdel(pflist->output); ft_memdel(pflist->fullflag); ft_memdel(pflist); return (ret); } int ft_dprintf(int fd, const char *format, ...) { t_printflist *pflist; va_list arg; int pos; if (!format) return (-1); if ((pos = ft_strlchr(format, '%')) < 0) return (write(fd, format, ft_strlen(format))); else { pflist = ft_printf_init_struct(format); ft_printf_putpart(format, 0, pos, pflist); va_start(arg, format); while (pos >= 0) { pos = ft_printf_flags(format, pos, arg, pflist); ft_printf_reinit_struct(pflist); } va_end(arg); return (ft_printf_return(fd, pflist)); } return (0); }