mirror of
https://github.com/troglobit/finit.git
synced 2026-11-28 20:58:24 +00:00
Add hexdump() debug helper function
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 file changed
+35
+35
@@ -25,6 +25,8 @@
|
|||||||
#define FINIT_UTIL_H_
|
#define FINIT_UTIL_H_
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#ifdef HAVE_TERMIOS_H
|
#ifdef HAVE_TERMIOS_H
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -130,6 +132,39 @@ static inline int suffix(char *path, size_t len, const char *sfx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void hexdump(const char *buf, size_t len)
|
||||||
|
{
|
||||||
|
size_t i, j;
|
||||||
|
|
||||||
|
for (i = 0; i < len; i += 16) {
|
||||||
|
printf("%08zx ", i);
|
||||||
|
|
||||||
|
for (j = 0; j < 8 && i + j < len; j++)
|
||||||
|
printf("%02x ", buf[i + j]);
|
||||||
|
|
||||||
|
if (j == 8) {
|
||||||
|
printf(" ");
|
||||||
|
} else {
|
||||||
|
for (; j < 8; j++)
|
||||||
|
printf(" ");
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 8; j < 16 && i + j < len; j++)
|
||||||
|
printf("%02x ", buf[i + j]);
|
||||||
|
|
||||||
|
for (; j < 16; j++)
|
||||||
|
printf(" ");
|
||||||
|
|
||||||
|
printf(" |");
|
||||||
|
for (j = 0; j < 16 && i + j < len; j++) {
|
||||||
|
char c = buf[i + j];
|
||||||
|
printf("%c", isprint(c) ? c : '.');
|
||||||
|
}
|
||||||
|
printf("|\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* FINIT_UTIL_H_ */
|
#endif /* FINIT_UTIL_H_ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user