From 0423b61aa8dd75b3141e13cf9276b8fa14ceb473 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Mon, 14 Jan 2019 23:32:53 +0100 Subject: add osmo_hexdump_buf() and test Add osmo_hexdump_buf() as an all-purpose hexdump function, which all other osmo_hexdump_*() implementations now call. It absorbs the static _osmo_hexdump(). Add tests for osmo_hexdump_buf(). Rationale: recently during patch review, a situation came up where two hexdumps in a single printf would have been useful. Now I've faced a similar situation again, in ongoing development. So I decided it is time to provide this API. The traditional osmo_hexdump() API returns a non-const char*, which should probably have been a const instead. Particularly this new function may return a string constant "" if the buf is NULL or empty, so return const char*. That is why the older implementations calling osmo_hexdump_buf() separately return the buffer instead of the const return value directly. Change-Id: I590595567b218b24e53c9eb1fd8736c0324d371d --- include/osmocom/core/utils.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/osmocom/core/utils.h') diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h index 987080e2..fe360b33 100644 --- a/include/osmocom/core/utils.h +++ b/include/osmocom/core/utils.h @@ -56,6 +56,9 @@ int osmo_hexparse(const char *str, uint8_t *b, int max_len); char *osmo_ubit_dump(const uint8_t *bits, unsigned int len); char *osmo_hexdump(const unsigned char *buf, int len); char *osmo_hexdump_nospc(const unsigned char *buf, int len); +const char *osmo_hexdump_buf(char *out_buf, size_t out_buf_size, const unsigned char *buf, int len, const char *delim, + bool delim_after_last); + char *osmo_osmo_hexdump_nospc(const unsigned char *buf, int len) __attribute__((__deprecated__)); #define osmo_static_assert(exp, name) typedef int dummy##name [(exp) ? 1 : -1] __attribute__((__unused__)); -- cgit v1.2.3