From 045906145d2235b7a1b0c2dfa6ace11850b8dbc1 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 16 Nov 2016 10:56:06 +0100 Subject: [PATCH] printf fd --- libftasm/includes/ft_printf.h | 4 +++- libftasm/includes/libft.h | 3 ++- libftasm/src/ft_printf/ft_printf.c | 27 +++++++++++++++++++++------ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/libftasm/includes/ft_printf.h b/libftasm/includes/ft_printf.h index 176d89df..9a439cec 100644 --- a/libftasm/includes/ft_printf.h +++ b/libftasm/includes/ft_printf.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */ -/* Updated: 2016/11/07 17:26:13 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 10:53:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,6 +42,8 @@ struct s_fmt t_conv conv; }; +int ft_vdprintf(int fd, const char *format, va_list ap); + extern t_conv g_convs[]; t_fmt *ft_fmt_init(void); diff --git a/libftasm/includes/libft.h b/libftasm/includes/libft.h index c6e8c0b6..5a0c26ca 100644 --- a/libftasm/includes/libft.h +++ b/libftasm/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2016/11/08 11:25:08 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 10:53:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -117,4 +117,5 @@ int ft_time_isrecent(time_t event); char *ft_path_notdir(char *path); int ft_printf(const char *format, ...); +int ft_dprintf(int fd, const char *format, ...); #endif diff --git a/libftasm/src/ft_printf/ft_printf.c b/libftasm/src/ft_printf/ft_printf.c index 3f37644a..a782bd0d 100644 --- a/libftasm/src/ft_printf/ft_printf.c +++ b/libftasm/src/ft_printf/ft_printf.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ -/* Updated: 2016/11/07 16:20:10 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 10:55:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,12 +27,26 @@ t_conv g_convs[] = int ft_printf(const char *format, ...) { - va_list ap1; + va_list ap; + + va_start(ap, format); + return(ft_vdprintf(0, format, ap)); +} + +int ft_dprintf(int fd, const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + return(ft_vdprintf(fd, format, ap)); +} + +int ft_vdprintf(int fd, const char *format, va_list ap) +{ char *str; char final[1000]; t_fmt *fmt; - va_start(ap1, format); str = ft_strdup(format); ft_bzero(final, 1000); while (*str) @@ -40,16 +54,17 @@ int ft_printf(const char *format, ...) if (*str == '%') { str++; - if (!(fmt = ft_printf_parse(&str, ap1))) + if (!(fmt = ft_printf_parse(&str, ap))) return (1); if (!fmt->valid) ft_strncat(final, &fmt->conversion, 1); else - ft_strcat(final, ft_transform(fmt, ap1)); + ft_strcat(final, ft_transform(fmt, ap)); } else ft_strncat(final, str++, 1); } - ft_putstr(final); + ft_putstr_fd(final, fd); + ft_strdel(&str); return (0); }