aboutsummaryrefslogtreecommitdiff
path: root/lib/hexdump.c
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2014-09-16 17:36:01 +0100
committerMister Oyster <oysterized@gmail.com>2017-12-22 16:23:43 +0100
commit6e3d2e279cd5ac2fddec491fe83a8ef5366e95ef (patch)
treefeb38a133059429fb86c31fa0dd5d0dd73f4ab74 /lib/hexdump.c
parent5bf44aaf5cc90f45b4f0e6e57c01bdd6735df392 (diff)
Provide a binary to hex conversion function
Provide a function to convert a buffer of binary data into an unterminated ascii hex string representation of that data. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: Vivek Goyal <vgoyal@redhat.com>
Diffstat (limited to 'lib/hexdump.c')
-rw-r--r--lib/hexdump.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/hexdump.c b/lib/hexdump.c
index 8499c8109..270773b91 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -59,6 +59,22 @@ int hex2bin(u8 *dst, const char *src, size_t count)
EXPORT_SYMBOL(hex2bin);
/**
+ * bin2hex - convert binary data to an ascii hexadecimal string
+ * @dst: ascii hexadecimal result
+ * @src: binary data
+ * @count: binary data length
+ */
+char *bin2hex(char *dst, const void *src, size_t count)
+{
+ const unsigned char *_src = src;
+
+ while (count--)
+ dst = hex_byte_pack(dst, *_src++);
+ return dst;
+}
+EXPORT_SYMBOL(bin2hex);
+
+/**
* hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
* @buf: data blob to dump
* @len: number of bytes in the @buf