aboutsummaryrefslogtreecommitdiff
path: root/scan_xlong.c
diff options
context:
space:
mode:
Diffstat (limited to 'scan_xlong.c')
-rw-r--r--scan_xlong.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/scan_xlong.c b/scan_xlong.c
new file mode 100644
index 0000000..1113433
--- /dev/null
+++ b/scan_xlong.c
@@ -0,0 +1,23 @@
+#include "scan.h"
+
+static inline int fromhex(unsigned char c) {
+ if (c>='0' && c<='9')
+ return c-'0';
+ else if (c>='A' && c<='F')
+ return c-'A'+10;
+ else if (c>='a' && c<='f')
+ return c-'a'+10;
+ return -1;
+}
+
+unsigned int scan_xlong(const char *src,unsigned long *dest) {
+ register const char *tmp=src;
+ register int l=0;
+ register unsigned char c;
+ while ((c=fromhex(*tmp))<16) {
+ l=(l<<4)+c;
+ ++tmp;
+ }
+ *dest=l;
+ return tmp-src;
+}