-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_pointers.c
More file actions
44 lines (36 loc) · 747 Bytes
/
print_pointers.c
File metadata and controls
44 lines (36 loc) · 747 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
#include <unistd.h>
#include "main.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
int print_pointers(va_list ap)
{
size_t i, start, end, count = 0;
uintptr_t addr_str;
void *addr = va_arg(ap, void *);
char temp, buffer[15];
addr_str = (uintptr_t)addr;
buffer[0] = '0';
buffer[1] = 'x';
for (i = 2; i < 15 && addr_str != 0; ++i)
{
int digit = addr_str % 16;
buffer[i] = (digit < 10) ? ('0' + digit) : ('a' + digit - 10);
addr_str /= 16;
}
start = 2;
end = i - 1;
while (start < end)
{
temp = buffer[start];
buffer[start] = buffer[end];
buffer[end] = temp;
++start;
--end;
}
buffer[i] = '\0';
for (i = 0; i < 14; ++i)
count += write(1, buffer + i, 1);
return (count);
}