-
Notifications
You must be signed in to change notification settings - Fork 0
/
pf_convert_pointer.c
63 lines (57 loc) · 1.93 KB
/
pf_convert_pointer.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pf_convert_pointer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mg <mg@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/10 11:06:22 by mg #+# #+# */
/* Updated: 2020/06/28 00:20:19 by mg ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void pf_reset_format_p(t_fmt *flag)
{
flag->group = 0;
flag->showsign = 0;
flag->space = 0;
flag->alt = 0;
}
static void pf_convert_pointer_internal(void *ptr, t_fmt *flag)
{
ssize_t len;
if (!flag->is_null)
{
flag->print = ft_itoa_base((unsigned long long int)ptr, flag->base);
flag->is_numeric = 1;
}
else if (IS_MACOS)
{
if (flag->precision == 0)
flag->print = ft_strdup("0x");
else
flag->print = ft_strdup("0x0");
if (!(len = 0) && flag->precision != -1)
while (++len < flag->precision)
ft_strappend_xo(&flag->print, "0");
if ((len = 2) && flag->precision == -1 && !flag->left && flag->pad)
while (++len < (ssize_t)flag->width)
ft_strappend_xo(&flag->print, "0");
}
else
{
flag->print = ft_strdup("(nil)");
flag->precision = -1;
}
}
void pf_convert_pointer(va_list *ap, t_fmt *flag)
{
void *ptr;
ptr = va_arg(*ap, void *);
flag->is_null = (ptr == NULL) ? 1 : 0;
pf_convert_pointer_internal(ptr, flag);
if (IS_MACOS)
pf_reset_format_p(flag);
if (!(flag->precision == -1))
flag->pad = 0;
}