printf fd

This commit is contained in:
Jack Halford 2016-11-16 10:56:06 +01:00
parent 99ebd75ca7
commit dd3633f4f7
3 changed files with 26 additions and 8 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}