-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.c
More file actions
54 lines (46 loc) · 1.18 KB
/
logging.c
File metadata and controls
54 lines (46 loc) · 1.18 KB
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
#include "logging.h"
#include <ctype.h>
void logging_display_memory_contents(const void *start, const void *last, FILE *fp)
{
size_t byte_count, group_count, i, n;
const size_t bytes_per_row = 32;
const unsigned char *p = (const unsigned char*) start;
byte_count = (const unsigned char*) last - (const unsigned char*) start + 1;
group_count = byte_count / bytes_per_row;
for (i = 0; i < group_count; i++) {
fprintf(fp, "%p:", p);
for (n = 0; n < bytes_per_row; n++)
fprintf(fp, " %02X", p[n]);
fprintf(fp, "\t");
for (n = 0; n < bytes_per_row; n++) {
if (isalnum(p[n]) || ispunct(p[n]))
fprintf(fp, "%c", p[n]);
else if (isspace(p[n]))
fprintf(fp, " ");
else
fprintf(fp, ".");
}
fprintf(fp, "\n");
p += bytes_per_row;
}
n = byte_count % bytes_per_row;
if (0 == n)
return;
fprintf(fp, "%p:", p);
for (i = 0; i < bytes_per_row; i++) {
if ((p + i) <= (unsigned char*) last)
fprintf(fp, " %02X", p[i]);
else
fprintf(fp, " ");
}
fprintf(fp, "\t");
for (i = 0; i < n; i++) {
if (isalnum(p[i]) || ispunct(p[i]))
fprintf(fp, "%c", p[i]);
else if (isspace(p[i]))
fprintf(fp, " ");
else
fprintf(fp, ".");
}
fprintf(fp, "\n");
}