-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_vdprintf.c
46 lines (42 loc) · 1.46 KB
/
ft_vdprintf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_vdprintf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/25 21:41:20 by akharrou #+# #+# */
/* Updated: 2019/07/29 01:07:41 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
/*
** Reproduction of the libc 'vdprintf()' function.
*/
int ft_vdprintf(int filedes, const char *format, va_list *args)
{
int32_t tt_bytes;
char *fstr;
size_t len;
size_t i;
if (!format)
return (0);
tt_bytes = 0;
while (*format != '\0')
{
i = 0;
while (format[i] != '\0' && format[i] != '%')
++i;
tt_bytes += write(filedes, format, i);
format += i;
if (*format == '%')
{
if (!(fstr = formatter(&format, args, &len)))
return (-1);
tt_bytes += write(filedes, fstr, len);
free(fstr);
}
}
va_end(*args);
return (tt_bytes);
}