a64l.c revision 153707
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: head/lib/libc/stdlib/a64l.c 153707 2005-12-24 22:37:59Z trhodes $"); 14 15#include <stdlib.h> 16#include <inttypes.h> 17 18#define ADOT 46 /* ASCII '.' */ 19#define ASLASH ADOT + 1 /* ASCII '/' */ 20#define A0 48 /* ASCII '0' */ 21#define AA 65 /* ASCII 'A' */ 22#define Aa 97 /* ASCII 'a' */ 23 24long 25a64l(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