42_minishell/libftx/printf/ft_vdprintf.c

55 lines
1.5 KiB
C
Raw Normal View History

2023-01-31 08:40:15 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_vdprintf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/12 14:34:28 by cchauvet #+# #+# */
2023-02-17 10:33:52 -05:00
/* Updated: 2023/02/17 16:31:29 by cchauvet ### ########.fr */
2023-01-31 08:40:15 -05: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)
{
2023-02-17 10:33:52 -05:00
ft_putchar_fd_p(fd, str[i]);
2023-01-31 08:40:15 -05:00
i++;
}
return (i);
}
int ft_vdprintf(int fd, const char *format, va_list va)
{
int i;
int upi;
if (format == NULL)
return (-1);
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);
}