-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
56 lines (46 loc) · 702 Bytes
/
_printf.c
File metadata and controls
56 lines (46 loc) · 702 Bytes
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
47
48
49
50
51
52
53
54
55
56
#include "main.h"
/**
* _printf - custom printf
* @format: format string
*
* Return: number of chars printed, -1 on error
*/
int _printf(const char *format, ...)
{
va_list ap;
pf_buffer_t b;
pf_format_t f;
const char *p;
if (format == NULL)
return (-1);
pf_buf_init(&b);
va_start(ap, format);
p = format;
while (*p != '\0')
{
if (*p != '%')
{
if (pf_buf_putc(&b, *p) == -1)
break;
p++;
continue;
}
p++;
if (*p == '\0')
{
b.err = 1;
break;
}
if (pf_parse(&p, &f, &ap) == -1)
{
b.err = 1;
break;
}
if (pf_handle(&b, &f, &ap) == -1)
break;
}
va_end(ap);
if (pf_buf_flush(&b) == -1 || b.err)
return (-1);
return (b.len);
}