Internal helper function for converting binary blobs to hex strings.
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 5 Sep 2007 10:42:25 +0000 (13:42 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 5 Sep 2007 10:42:25 +0000 (13:42 +0300)
(transplanted from 5b4c099c3fdb253d5ed440333cb99ad56af24d9f)

rpmdb/header_internal.c
rpmdb/header_internal.h

index 9d81c7e..969ca11 100644 (file)
@@ -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;
+}
+    
+    
index a85a219..483d8a5 100644 (file)
@@ -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