summaryrefslogtreecommitdiffstats
path: root/src/debug.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2009-02-28 13:08:01 +0000
committerHarald Welte <laforge@gnumonks.org>2009-02-28 13:08:01 +0000
commit3cc4bf517f4eb7f5ab0dd9e02cf7a7bc3106e1ff (patch)
tree6743514de65bc3ba99cd1f94634940c6117d04ab /src/debug.c
parent51f38457e54a9d8c50d7d77e9b7e92465475cf84 (diff)
make hexdump return a 'char *' rather than printing by itself
Diffstat (limited to 'src/debug.c')
-rw-r--r--src/debug.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/debug.c b/src/debug.c
index c071df0a9..735fce391 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -127,12 +127,22 @@ void debugp(unsigned int subsys, char *file, int line, int cont, const char *for
fflush(outfd);
}
-void hexdump(unsigned char *buf, int len)
+static char hexd_buff[4096];
+
+char *hexdump(unsigned char *buf, int len)
{
int i;
+ char *cur = hexd_buff;
+
+ hexd_buff[0] = 0;
for (i = 0; i < len; i++) {
- fprintf(stdout, "%02x ", buf[i]);
+ int len_remain = sizeof(hexd_buff) - (cur - hexd_buff);
+ int rc = snprintf(cur, len_remain, "%02x ", buf[i]);
+ if (rc <= 0)
+ break;
+ cur += rc;
}
- fprintf(stdout, "\n");
+ hexd_buff[sizeof(hexd_buff)-1] = 0;
+ return hexd_buff;
}