xref: /freebsd/lib/libc/stdlib/a64l.c (revision 5e3190f700637fcfc1a52daeaa4a031fdd2557c7)
1 /*-
2  * Written by J.T. Conklin <jtc@netbsd.org>.
3  * Public domain.
4  */
5 
6 #if 0
7 #if defined(LIBC_SCCS) && !defined(lint)
8 __RCSID("$NetBSD: a64l.c,v 1.8 2000/01/22 22:19:19 mycroft Exp $");
9 #endif /* not lint */
10 #endif
11 
12 #include <sys/cdefs.h>
13 #include <stdlib.h>
14 #include <inttypes.h>
15 
16 #define	ADOT	46		/* ASCII '.' */
17 #define	ASLASH	47		/* ASCII '/' */
18 #define	A0	48		/* ASCII '0' */
19 #define	AA	65		/* ASCII 'A' */
20 #define	Aa	97		/* ASCII 'a' */
21 
22 long
23 a64l(const char *s)
24 {
25 	long shift;
26 	int digit, i, value;
27 
28 	value = 0;
29 	shift = 0;
30 	for (i = 0; *s != '\0' && i < 6; i++, s++) {
31 		if (*s <= ASLASH)
32 			digit = *s - ASLASH + 1;
33 		else if (*s <= A0 + 9)
34 			digit = *s - A0 + 2;
35 		else if (*s <= AA + 25)
36 			digit = *s - AA + 12;
37 		else
38 			digit = *s - Aa + 38;
39 
40 		value |= digit << shift;
41 		shift += 6;
42 	}
43 	return (value);
44 }
45