aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-07-30 11:43:30 +0200
committerHarald Welte <laforge@gnumonks.org>2010-07-30 11:47:50 +0200
commitdee47cd14dc426c45253f576edaae9fe9c4e028a (patch)
treee8f45b47bf1ac3914184b10c6abba314822b6b28
parent40481e895453c53d71f2f254b931b77c830c9e0a (diff)
add new hexdump_nospc() function0.1.15
-rw-r--r--include/osmocore/utils.h1
-rw-r--r--src/utils.c14
2 files changed, 13 insertions, 2 deletions
diff --git a/include/osmocore/utils.h b/include/osmocore/utils.h
index 07af180..3574f7f 100644
--- a/include/osmocore/utils.h
+++ b/include/osmocore/utils.h
@@ -19,5 +19,6 @@ uint8_t char2bcd(char c);
int hexparse(const char *str, uint8_t *b, int max_len);
char *hexdump(const unsigned char *buf, int len);
+char *hexdump_nospc(const unsigned char *buf, int len);
#endif
diff --git a/src/utils.c b/src/utils.c
index a6c2d6d..2155885 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -78,7 +78,7 @@ int hexparse(const char *str, uint8_t *b, int max_len)
static char hexd_buff[4096];
-char *hexdump(const unsigned char *buf, int len)
+static char *_hexdump(const unsigned char *buf, int len, char *delim)
{
int i;
char *cur = hexd_buff;
@@ -86,7 +86,7 @@ char *hexdump(const unsigned char *buf, int len)
hexd_buff[0] = 0;
for (i = 0; i < len; i++) {
int len_remain = sizeof(hexd_buff) - (cur - hexd_buff);
- int rc = snprintf(cur, len_remain, "%02x ", buf[i]);
+ int rc = snprintf(cur, len_remain, "%02x%s", buf[i], delim);
if (rc <= 0)
break;
cur += rc;
@@ -94,3 +94,13 @@ char *hexdump(const unsigned char *buf, int len)
hexd_buff[sizeof(hexd_buff)-1] = 0;
return hexd_buff;
}
+
+char *hexdump(const unsigned char *buf, int len)
+{
+ return _hexdump(buf, len, " ");
+}
+
+char *hexdump_nospc(const unsigned char *buf, int len)
+{
+ return _hexdump(buf, len, "");
+}