2022-10-06 20:30:03 -04:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* ft_vdprintf.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
2022-10-23 13:01:50 -04:00
|
|
|
/* Created: 2022/10/12 14:34:28 by cchauvet #+# #+# */
|
2022-12-11 13:27:25 -05:00
|
|
|
/* Updated: 2022/12/11 19:23:34 by cchauvet ### ########.fr */
|
2022-10-06 20:30:03 -04:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
2022-10-23 13:01:50 -04:00
|
|
|
#include "ft_printf.h"
|
|
|
|
|
|
|
|
static int ft_dprintseg(int fd, const char *str)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (str[i] != '\0' && ft_skipflag(str + i) == 0)
|
2022-12-11 13:27:25 -05:00
|
|
|
{
|
|
|
|
ft_putchar_fd(fd, str[i]);
|
|
|
|
i++;
|
|
|
|
}
|
2022-10-23 13:01:50 -04:00
|
|
|
return (i);
|
|
|
|
}
|
2022-10-06 20:30:03 -04:00
|
|
|
|
2022-10-10 13:33:47 -04:00
|
|
|
int ft_vdprintf(int fd, const char *format, va_list va)
|
2022-10-06 20:30:03 -04:00
|
|
|
{
|
2022-10-23 13:01:50 -04:00
|
|
|
int i;
|
|
|
|
int upi;
|
2022-10-06 20:30:03 -04:00
|
|
|
|
2022-11-23 10:11:06 -05:00
|
|
|
if (format == NULL)
|
|
|
|
return (-1);
|
2022-10-23 13:01:50 -04:00
|
|
|
i = 0;
|
|
|
|
while (format[0] != 0)
|
|
|
|
{
|
|
|
|
if (ft_skipflag(format) == 0)
|
|
|
|
{
|
|
|
|
upi = ft_dprintseg(fd, format);
|
|
|
|
format += upi;
|
|
|
|
i += upi;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
upi = ft_dprintflag(fd, format, va);
|
|
|
|
if (upi == -1)
|
|
|
|
return (-1);
|
|
|
|
format += ft_skipflag(format);
|
|
|
|
i += upi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (i);
|
2022-10-06 20:30:03 -04:00
|
|
|
}
|