summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c43
-rw-r--r--src/shared/util.h2
2 files changed, 45 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 8b8d2fbc5e..7e17851fcd 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -6347,3 +6347,46 @@ char* mount_test_option(const char *haystack, const char *needle) {
return hasmntopt(&me, needle);
}
+
+void hexdump(FILE *f, const void *p, size_t s) {
+ const uint8_t *b = p;
+ unsigned n = 0;
+
+ assert(s == 0 || b);
+
+ while (s > 0) {
+ size_t i;
+
+ fprintf(f, "%04x ", n);
+
+ for (i = 0; i < 16; i++) {
+
+ if (i >= s)
+ fputs(" ", f);
+ else
+ fprintf(f, "%02x ", b[i]);
+
+ if (i == 7)
+ fputc(' ', f);
+ }
+
+ fputc(' ', f);
+
+ for (i = 0; i < 16; i++) {
+
+ if (i >= s)
+ fputc(' ', f);
+ else
+ fputc(isprint(b[i]) ? (char) b[i] : '.', f);
+ }
+
+ fputc('\n', f);
+
+ if (s < 16)
+ break;
+
+ n += 16;
+ b += 16;
+ s -= 16;
+ }
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index e99f8d1123..c596d795d3 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -914,3 +914,5 @@ const char *personality_to_string(unsigned long);
uint64_t physical_memory(void);
char* mount_test_option(const char *haystack, const char *needle);
+
+void hexdump(FILE *f, const void *p, size_t s);