diff options
author | Harald Welte <laforge@gnumonks.org> | 2010-07-30 11:43:30 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2010-07-30 11:47:50 +0200 |
commit | dee47cd14dc426c45253f576edaae9fe9c4e028a (patch) | |
tree | e8f45b47bf1ac3914184b10c6abba314822b6b28 /src | |
parent | 40481e895453c53d71f2f254b931b77c830c9e0a (diff) |
add new hexdump_nospc() function
Diffstat (limited to 'src')
-rw-r--r-- | src/utils.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/utils.c b/src/utils.c index a6c2d6d2..21558857 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, ""); +} |