From c2e3cde667fc1345e33535ac9e1feb5b437602ec Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 5 Sep 2007 13:42:25 +0300 Subject: [PATCH] Internal helper function for converting binary blobs to hex strings. (transplanted from 5b4c099c3fdb253d5ed440333cb99ad56af24d9f) --- rpmdb/header_internal.c | 19 +++++++++++++++++++ rpmdb/header_internal.h | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/rpmdb/header_internal.c b/rpmdb/header_internal.c index 9d81c7e..969ca11 100644 --- a/rpmdb/header_internal.c +++ b/rpmdb/header_internal.c @@ -172,3 +172,22 @@ void headerDump(Header h, FILE *f, int flags, /*@=type@*/ /*@=sizeoftype@*/ /*@=boundsread@*/ + +char * bin2hex(const char *data, size_t size) +{ + static char hex[] = "0123456789abcdef"; + const char * s = data; + char * t, * val; + val = t = xmalloc(size * 2 + 1); + while (size-- > 0) { + unsigned int i; + i = *s++; + *t++ = hex[ (i >> 4) & 0xf ]; + *t++ = hex[ (i ) & 0xf ]; + } + *t = '\0'; + + return val; +} + + diff --git a/rpmdb/header_internal.h b/rpmdb/header_internal.h index a85a219..483d8a5 100644 --- a/rpmdb/header_internal.h +++ b/rpmdb/header_internal.h @@ -202,6 +202,14 @@ void headerDump(Header h, FILE *f, int flags, /*@modifies f, fileSystem @*/; #define HEADER_DUMP_INLINE 1 +/* XXX not perhaps the right place but.. */ +/** \ingroup header + * Convert binary blob to printable hex string + * @param data binary data + * @param size size of data in bytes + */ +char * bin2hex(const char *data, size_t count); + #ifdef __cplusplus } #endif -- 2.7.4