-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathinspect-utils.c
45 lines (40 loc) · 962 Bytes
/
inspect-utils.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
/*
* inspect-utils.c
* Copyright (c) 2017-2018 Arkadiusz Bokowy
*
* This file is a part of [open]aptx.
*
* This project is licensed under the terms of the MIT license.
*
*/
#include "inspect-utils.h"
#include <stdio.h>
#include <string.h>
int diffint(const char * label, int a, int b) {
if (a == b)
return 0;
fprintf(stderr, "%s: %d != %d (%d)\n", label, a, b, b - a);
return a - b;
}
int diffmem(const char * label, const void * a, const void * b, size_t n) {
if (a == b)
return 0;
if (n == 0 || a == NULL || b == NULL) {
fprintf(stderr, "%s: %p != %p\n", label, a, b);
return a - b;
}
int ret = 0;
if ((ret = memcmp(a, b, n)) == 0)
return ret;
hexdump(label, a, n);
hexdump(label, b, n);
return ret;
}
void hexdump(const char * label, const void * mem, size_t n) {
fprintf(stderr, "%s: ", label);
while (n--) {
fprintf(stderr, "%.2x", *(unsigned char *)mem);
mem = (unsigned char *)mem + 1;
}
fprintf(stderr, "\n");
}