This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Neels Hofmeyr gerrit-no-reply at lists.osmocom.orgNeels Hofmeyr has uploaded this change for review. ( https://gerrit.osmocom.org/12671 Change subject: add osmo_hexdump_b(), osmo_hexdump_nospc_b() ...................................................................... add osmo_hexdump_b(), osmo_hexdump_nospc_b() Add osmo_hexdump_b() and osmo_hexdump_nospc_b() to use a second static buffer, allowing more than one hexdump per printf()-like call. 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. Naming: before, I named functions that use a secondary string buffer with a '2' suffix, like osmo_plmn_name() and osmo_plmn_name2(). This time, I decided to use a '_b' suffix, osmo_hexdump_b(), instead. The reason is, by now I think that '2' is a bad choice for secondary-buffer functions: the '2' suffix is already used for introducing a newer API version of function signatures. If we, for example, introduce an osmo_hexdump() that has no final delimiter after the last byte, that would qualify for osmo_hexdump2(); and that would confuse with the implementation simply using a secondary buffer. Sometimes during code review, I assume that the existence of a foo2() function means the patch submitter should use foo2() instead of foo(), and am annoyed by my previous choice of overloading the '2' suffix with a secondary meaning besides "this is newer API". Change-Id: Ia48fc6b984f06b972a6846b173b8cf8d30737460 --- M include/osmocom/core/utils.h M src/utils.c 2 files changed, 25 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/71/12671/1 diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h index ff16cf4..ffe6cdd 100644 --- a/include/osmocom/core/utils.h +++ b/include/osmocom/core/utils.h @@ -55,7 +55,9 @@ char *osmo_ubit_dump(const uint8_t *bits, unsigned int len); char *osmo_hexdump(const unsigned char *buf, int len); +char *osmo_hexdump_b(const unsigned char *buf, int len); char *osmo_hexdump_nospc(const unsigned char *buf, int len); +char *osmo_hexdump_nospc_b(const unsigned char *buf, int len); 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); diff --git a/src/utils.c b/src/utils.c index c21b4ad..06c2f8a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -217,6 +217,7 @@ } static char hexd_buff[4096]; +static char hexd_buff2[4096]; static const char hex_chars[] = "0123456789abcdef"; /*! Convert binary sequence to hexadecimal ASCII string. @@ -320,6 +321,17 @@ return osmo_hexdump_buf(hexd_buff, sizeof(hexd_buff), buf, len, " ", true); } +/*! Same as osmo_hexdump() but use a separate static buffer. + * Allows passing a second osmo_hexdump() as print format argument. + * \param[in] buf pointer to sequence of bytes. + * \param[in] len length of buf in number of bytes. + * \returns pointer to zero-terminated string. + */ +char *osmo_hexdump_b(const unsigned char *buf, int len) +{ + return osmo_hexdump_buf(hexd_buff2, sizeof(hexd_buff2), buf, len, " ", true); +} + /*! Convert binary sequence to hexadecimal ASCII string * \param[in] buf pointer to sequence of bytes * \param[in] len length of buf in number of bytes @@ -336,6 +348,17 @@ return osmo_hexdump_buf(hexd_buff, sizeof(hexd_buff), buf, len, "", true); } +/*! Same as osmo_hexdump_nospc() but use a separate static buffer. + * Allows passing a second osmo_hexdump() as print format argument. + * \param[in] buf pointer to sequence of bytes + * \param[in] len length of buf in number of bytes + * \returns pointer to zero-terminated string + */ +char *osmo_hexdump_nospc_b(const unsigned char *buf, int len) +{ + return osmo_hexdump_buf(hexd_buff2, sizeof(hexd_buff2), buf, len, "", true); +} + /* Compat with previous typo to preserve abi */ char *osmo_osmo_hexdump_nospc(const unsigned char *buf, int len) #if defined(__MACH__) && defined(__APPLE__) -- To view, visit https://gerrit.osmocom.org/12671 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-MessageType: newchange Gerrit-Change-Id: Ia48fc6b984f06b972a6846b173b8cf8d30737460 Gerrit-Change-Number: 12671 Gerrit-PatchSet: 1 Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190122/92bf5415/attachment.htm>