1 /* 2 * Written by J.T. Conklin <jtc@NetBSD.org>. 3 * Public domain. 4 */ 5 6 #include <sys/cdefs.h> 7 #if defined(LIBC_SCCS) && !defined(lint) 8 __RCSID("$NetBSD: a64l.c,v 1.10 2012/06/08 11:15:26 abs Exp $"); 9 #endif 10 11 #include "namespace.h" 12 13 #include <assert.h> 14 #include <stdlib.h> 15 16 #ifdef __weak_alias __weak_alias(a64l,_a64l)17__weak_alias(a64l,_a64l) 18 #endif 19 20 long 21 a64l(const char *s) 22 { 23 long value, digit, shift; 24 int i; 25 26 _DIAGASSERT(s != NULL); 27 28 value = 0; 29 shift = 0; 30 for (i = 0; *s && i < 6; i++, s++) { 31 if (*s <= '/') 32 digit = *s - '.'; 33 else if (*s <= '9') 34 digit = *s - '0' + 2; 35 else if (*s <= 'Z') 36 digit = *s - 'A' + 12; 37 else 38 digit = *s - 'a' + 38; 39 40 value |= digit << shift; 41 shift += 6; 42 } 43 44 return (long) value; 45 } 46