summaryrefslogtreecommitdiff
path: root/util/compat.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/compat.c')
-rw-r--r--util/compat.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/util/compat.c b/util/compat.c
new file mode 100644
index 0000000..aca558a
--- /dev/null
+++ b/util/compat.c
@@ -0,0 +1,24 @@
+int
+hextobyte (const char *s)
+{
+ int c;
+
+ if ( *s >= '0' && *s <= '9' )
+ c = 16 * (*s - '0');
+ else if ( *s >= 'A' && *s <= 'F' )
+ c = 16 * (10 + *s - 'A');
+ else if ( *s >= 'a' && *s <= 'f' )
+ c = 16 * (10 + *s - 'a');
+ else
+ return -1;
+ s++;
+ if ( *s >= '0' && *s <= '9' )
+ c += *s - '0';
+ else if ( *s >= 'A' && *s <= 'F' )
+ c += 10 + *s - 'A';
+ else if ( *s >= 'a' && *s <= 'f' )
+ c += 10 + *s - 'a';
+ else
+ return -1;
+ return c;
+}