diff options
author | Mimi Zohar <zohar@linux.vnet.ibm.com> | 2010-11-23 23:50:31 +0100 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2010-11-28 22:55:11 +0100 |
commit | dc88e46029486ed475c71fe1bb696d39511ac8fe (patch) | |
tree | 75f5bbf30480d4126315211ea6fb3af395e5f09c /lib/hexdump.c | |
parent | security: Define CAP_SYSLOG (diff) | |
download | linux-dc88e46029486ed475c71fe1bb696d39511ac8fe.tar.xz linux-dc88e46029486ed475c71fe1bb696d39511ac8fe.zip |
lib: hex2bin converts ascii hexadecimal string to binary
Similar to the kgdb_hex2mem() code, hex2bin converts a string
to binary using the hex_to_bin() library call.
Changelog:
- Replace parameter names with src/dst (based on David Howell's comment)
- Add 'const' where needed (based on David Howell's comment)
- Replace int with size_t (based on David Howell's comment)
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Acked-by: Serge E. Hallyn <serge@hallyn.com>
Acked-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'lib/hexdump.c')
-rw-r--r-- | lib/hexdump.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/hexdump.c b/lib/hexdump.c index 5d7a4802c562..b66b2bd67952 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c @@ -34,6 +34,22 @@ int hex_to_bin(char ch) EXPORT_SYMBOL(hex_to_bin); /** + * hex2bin - convert an ascii hexadecimal string to its binary representation + * @dst: binary result + * @src: ascii hexadecimal string + * @count: result length + */ +void hex2bin(u8 *dst, const char *src, size_t count) +{ + while (count--) { + *dst = hex_to_bin(*src++) << 4; + *dst += hex_to_bin(*src++); + dst++; + } +} +EXPORT_SYMBOL(hex2bin); + +/** * 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 |