-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle_pointer.c
48 lines (42 loc) · 1.33 KB
/
handle_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_pointer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bde-koni <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/29 14:01:37 by bde-koni #+# #+# */
/* Updated: 2024/11/29 16:22:00 by bde-koni ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
size_t handle_pointer(void *p)
{
size_t count;
count = 0;
if (p == NULL)
{
ft_putstr("(nil)");
count += 5;
}
else
{
ft_putaddress(p);
count += 2;
count += ft_hexalen((uintptr_t)p);
}
return (count);
}
void ft_puthexa_ptr(uintptr_t x)
{
if (x >= 16)
ft_puthexa_ptr(x / 16);
ft_putchar("0123456789abcdef"[x % 16]);
}
void ft_putaddress(void *p)
{
uintptr_t ptr;
ptr = (uintptr_t)p;
ft_putstr("0x");
ft_puthexa_ptr(ptr);
}