xref: /freebsd/lib/libc/stdlib/a64l.c (revision d3d381b2b194b4d24853e92eecef55f262688d1a)
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 __FBSDID("$FreeBSD$");
14 
15 #include <stdlib.h>
16 #include <inttypes.h>
17 
18 #define	ADOT	46		/* ASCII '.' */
19 #define	ASLASH	47		/* ASCII '/' */
20 #define	A0	48		/* ASCII '0' */
21 #define	AA	65		/* ASCII 'A' */
22 #define	Aa	97		/* ASCII 'a' */
23 
24 long
25 a64l(const char *s)
26 {
27 	long shift;
28 	int digit, i, value;
29 
30 	value = 0;
31 	shift = 0;
32 	for (i = 0; *s != '\0' && i < 6; i++, s++) {
33 		if (*s <= ASLASH)
34 			digit = *s - ASLASH + 1;
35 		else if (*s <= A0 + 9)
36 			digit = *s - A0 + 2;
37 		else if (*s <= AA + 25)
38 			digit = *s - AA + 12;
39 		else
40 			digit = *s - Aa + 38;
41 
42 		value |= digit << shift;
43 		shift += 6;
44 	}
45 	return (value);
46 }
47