-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.c
More file actions
48 lines (36 loc) · 1.09 KB
/
debug.c
File metadata and controls
48 lines (36 loc) · 1.09 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
/*
* Copyright (c) 2012-2022 Israel Jacquez
* See LICENSE for details.
*
* Israel Jacquez <mrkotfw@gmail.com>
*/
#include <stdio.h>
#include <string.h>
#include "debug.h"
#include <math_utilities.h>
void
debug_hexdump(const char *buffer, size_t size, uint32_t max_width)
{
if (size == 0) {
return;
}
max_width = min(min(size, max_width), 80U);
(void)fputs(" ", stderr);
for (uint32_t i = 0; i < max_width; i++) {
(void)fprintf(stderr, " [1;35m%02X[m", i);
}
uint32_t fold;
fold = 0;
for (uint32_t i = 0; i < size; i++) {
const bool eol = ((fold % max_width) == 0);
const bool last_byte = ((i + 1) == size);
if (eol && !last_byte) {
(void)fprintf(stderr, "\n[1;35m%02X[m %02X", i, (uint8_t)buffer[i]);
} else {
(void)fprintf(stderr, " %02X", (uint8_t)buffer[i]);
}
fold++;
}
(void)putc('\n', stderr);
(void)fflush(stderr);
}