xref: /freebsd/lib/libc/stdlib/a64l.c (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
1257551c6STom Rhodes /*-
2257551c6STom Rhodes  * Written by J.T. Conklin <jtc@netbsd.org>.
3257551c6STom Rhodes  * Public domain.
4257551c6STom Rhodes  */
5257551c6STom Rhodes 
6257551c6STom Rhodes #if 0
7257551c6STom Rhodes #if defined(LIBC_SCCS) && !defined(lint)
8257551c6STom Rhodes __RCSID("$NetBSD: a64l.c,v 1.8 2000/01/22 22:19:19 mycroft Exp $");
9257551c6STom Rhodes #endif /* not lint */
10257551c6STom Rhodes #endif
11257551c6STom Rhodes 
12257551c6STom Rhodes #include <sys/cdefs.h>
13257551c6STom Rhodes #include <stdlib.h>
14257551c6STom Rhodes #include <inttypes.h>
15257551c6STom Rhodes 
16257551c6STom Rhodes #define	ADOT	46		/* ASCII '.' */
171761ec10SJung-uk Kim #define	ASLASH	47		/* ASCII '/' */
18257551c6STom Rhodes #define	A0	48		/* ASCII '0' */
19257551c6STom Rhodes #define	AA	65		/* ASCII 'A' */
20257551c6STom Rhodes #define	Aa	97		/* ASCII 'a' */
21257551c6STom Rhodes 
22257551c6STom Rhodes long
a64l(const char * s)23257551c6STom Rhodes a64l(const char *s)
24257551c6STom Rhodes {
25257551c6STom Rhodes 	long shift;
26257551c6STom Rhodes 	int digit, i, value;
27257551c6STom Rhodes 
28257551c6STom Rhodes 	value = 0;
29257551c6STom Rhodes 	shift = 0;
30257551c6STom Rhodes 	for (i = 0; *s != '\0' && i < 6; i++, s++) {
31257551c6STom Rhodes 		if (*s <= ASLASH)
32257551c6STom Rhodes 			digit = *s - ASLASH + 1;
33257551c6STom Rhodes 		else if (*s <= A0 + 9)
34257551c6STom Rhodes 			digit = *s - A0 + 2;
35257551c6STom Rhodes 		else if (*s <= AA + 25)
36257551c6STom Rhodes 			digit = *s - AA + 12;
37257551c6STom Rhodes 		else
38257551c6STom Rhodes 			digit = *s - Aa + 38;
39257551c6STom Rhodes 
40257551c6STom Rhodes 		value |= digit << shift;
41257551c6STom Rhodes 		shift += 6;
42257551c6STom Rhodes 	}
43257551c6STom Rhodes 	return (value);
44257551c6STom Rhodes }
45