diff options
-rw-r--r-- | include/linux/kernel.h | 2 | ||||
-rw-r--r-- | lib/hexdump.c | 18 |
2 files changed, 20 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 05f332afc9e0..8317ec4b9f3b 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -375,6 +375,8 @@ static inline char *pack_hex_byte(char *buf, u8 byte) | |||
375 | return buf; | 375 | return buf; |
376 | } | 376 | } |
377 | 377 | ||
378 | extern int hex_to_bin(char ch); | ||
379 | |||
378 | #ifndef pr_fmt | 380 | #ifndef pr_fmt |
379 | #define pr_fmt(fmt) fmt | 381 | #define pr_fmt(fmt) fmt |
380 | #endif | 382 | #endif |
diff --git a/lib/hexdump.c b/lib/hexdump.c index 1bd6a9779774..5d7a4802c562 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c | |||
@@ -16,6 +16,24 @@ const char hex_asc[] = "0123456789abcdef"; | |||
16 | EXPORT_SYMBOL(hex_asc); | 16 | EXPORT_SYMBOL(hex_asc); |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * hex_to_bin - convert a hex digit to its real value | ||
20 | * @ch: ascii character represents hex digit | ||
21 | * | ||
22 | * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad | ||
23 | * input. | ||
24 | */ | ||
25 | int hex_to_bin(char ch) | ||
26 | { | ||
27 | if ((ch >= '0') && (ch <= '9')) | ||
28 | return ch - '0'; | ||
29 | ch = tolower(ch); | ||
30 | if ((ch >= 'a') && (ch <= 'f')) | ||
31 | return ch - 'a' + 10; | ||
32 | return -1; | ||
33 | } | ||
34 | EXPORT_SYMBOL(hex_to_bin); | ||
35 | |||
36 | /** | ||
19 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory | 37 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory |
20 | * @buf: data blob to dump | 38 | * @buf: data blob to dump |
21 | * @len: number of bytes in the @buf | 39 | * @len: number of bytes in the @buf |