xref: /dragonfly/lib/libc/stdlib/a64l.c (revision 479ab7f0)
1 /*-
2  * Written by J.T. Conklin <jtc@netbsd.org>.
3  * Public domain.
4  *
5  * $NetBSD: a64l.c,v 1.8 2000/01/22 22:19:19 mycroft Exp $
6  * $FreeBSD: src/lib/libc/stdlib/a64l.c,v 1.2 2006/05/19 19:06:38 jkim Exp $
7  */
8 
9 #include <stdlib.h>
10 #include <inttypes.h>
11 
12 long
13 a64l(const char *s)
14 {
15 	long shift;
16 	int digit, i, value;
17 
18 	value = 0;
19 	shift = 0;
20 	for (i = 0; *s != '\0' && i < 6; i++, s++) {
21 		if (*s <= '/')
22 			digit = *s - '/' + 1;
23 		else if (*s <= '0' + 9)
24 			digit = *s - '0' + 2;
25 		else if (*s <= 'A' + 25)
26 			digit = *s - 'A' + 12;
27 		else
28 			digit = *s - 'a' + 38;
29 
30 		value |= digit << shift;
31 		shift += 6;
32 	}
33 	return (value);
34 }
35