diff options
author | Matt Fleming <matt.fleming@linux.intel.com> | 2011-05-18 15:55:21 +0100 |
---|---|---|
committer | Matt Fleming <matt.fleming@intel.com> | 2011-11-02 11:23:43 +0000 |
commit | dd5e4935f3e2f8f1940c72d9c3b39a926300c42e (patch) | |
tree | 4d356110c0a6db7fd90f155953585ea40aa740ea | |
parent | 2092e06957a6fc612a27296c1a50b391d31dbd41 (diff) | |
download | syslinux-dd5e4935f3e2f8f1940c72d9c3b39a926300c42e.tar.gz syslinux-dd5e4935f3e2f8f1940c72d9c3b39a926300c42e.tar.xz syslinux-dd5e4935f3e2f8f1940c72d9c3b39a926300c42e.zip |
com32: Add unhexchar
Add a C implementation of unhexchar() for use in C code. This
implementation should be an exact duplicate of the old asm version.
Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
-rw-r--r-- | com32/include/stdio.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/com32/include/stdio.h b/com32/include/stdio.h index 238c396e..902a0e80 100644 --- a/com32/include/stdio.h +++ b/com32/include/stdio.h @@ -119,4 +119,27 @@ __extern void perror(const char *); __extern int rename(const char *, const char *); +/* + * unhexchar: Convert a hexadecimal digit to the equivalent number + * + * Returns 0 if 'data' was converted succesfully, -1 otherwise. + */ +static inline int unhexchar(char *data) +{ + char num = *data; + + if (num >= '0' && num <= '9') { + *data = num - '0'; + return 0; + } else { + num |= 0x20; /* upper case -> lower case */ + if (num >= 'a' && num <= 'f') { + *data = num - 'a' - 10; + return 0; + } + } + + return -1; +} + #endif /* _STDIO_H */ |