From 49de98994f234e93cc37e2f01d2927a05880a7e7 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 8 Sep 2016 16:04:47 +0200 Subject: Allow disabling hexdump header Signed-off-by: Szczepan Zalega --- include/misc.h | 2 +- misc.cc | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/misc.h b/include/misc.h index a5d9e6d..cccd830 100644 --- a/include/misc.h +++ b/include/misc.h @@ -15,7 +15,7 @@ typename T::CommandPayload get_payload(){ } - std::string hexdump(const char *p, size_t size); + std::string hexdump(const char *p, size_t size, bool print_header=true); uint32_t stm_crc32(const uint8_t *data, size_t size); } } diff --git a/misc.cc b/misc.cc index a31d9bc..d004d0f 100644 --- a/misc.cc +++ b/misc.cc @@ -6,14 +6,16 @@ namespace nitrokey { namespace misc { -std::string hexdump(const char *p, size_t size) { +std::string hexdump(const char *p, size_t size, bool print_header) { std::stringstream out; char formatbuf[128]; const char *pstart = p; for (const char *pend = p + size; p < pend;) { - snprintf(formatbuf, 128, "%04lx\t", p - pstart); - out << formatbuf; + if (print_header){ + snprintf(formatbuf, 128, "%04lx\t", p - pstart); + out << formatbuf; + } for (const char *le = p + 16; p < le && p < pend; p++) { snprintf(formatbuf, 128, "%02x ", uint8_t(*p)); -- cgit v1.2.3