-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_vsprintf.c
45 lines (41 loc) · 1.37 KB
/
ft_vsprintf.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_vsprintf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/25 21:41:59 by akharrou #+# #+# */
/* Updated: 2019/05/23 14:30:40 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
/*
** Reproduction of the libc 'vsprintf()' function.
*/
int ft_vsprintf(char *str, const char *format, va_list *args)
{
char *fstr;
size_t pos;
size_t len;
if (!format)
return (0);
pos = 0;
while (*format)
{
if (*format == '%')
{
fstr = formatter(&format, args, &len);
if (!fstr)
return (-1);
ft_memcpy(str + pos, fstr, len);
pos += len;
free(fstr);
}
else
str[pos++] = *format++;
}
va_end(*args);
str[pos] = '\0';
return (pos);
}