11f10b502Sjtc /* 299410184Ssalo * Written by J.T. Conklin <jtc@NetBSD.org>. 39ae90685Sjtc * Public domain. 41f10b502Sjtc */ 51f10b502Sjtc 6bd906777Schristos #include <sys/cdefs.h> 71f10b502Sjtc #if defined(LIBC_SCCS) && !defined(lint) 8*7d974f9aSabs __RCSID("$NetBSD: a64l.c,v 1.10 2012/06/08 11:15:26 abs Exp $"); 91f10b502Sjtc #endif 101f10b502Sjtc 1143fa6fe3Sjtc #include "namespace.h" 12b48252f3Slukem 13b48252f3Slukem #include <assert.h> 14bd906777Schristos #include <stdlib.h> 15bd906777Schristos 1643fa6fe3Sjtc #ifdef __weak_alias __weak_alias(a64l,_a64l)1760549036Smycroft__weak_alias(a64l,_a64l) 1843fa6fe3Sjtc #endif 1943fa6fe3Sjtc 201f10b502Sjtc long 21*7d974f9aSabs a64l(const char *s) 221f10b502Sjtc { 231f10b502Sjtc long value, digit, shift; 241f10b502Sjtc int i; 251f10b502Sjtc 26b48252f3Slukem _DIAGASSERT(s != NULL); 27b48252f3Slukem 281f10b502Sjtc value = 0; 291f10b502Sjtc shift = 0; 301f10b502Sjtc for (i = 0; *s && i < 6; i++, s++) { 311f10b502Sjtc if (*s <= '/') 321f10b502Sjtc digit = *s - '.'; 331f10b502Sjtc else if (*s <= '9') 341f10b502Sjtc digit = *s - '0' + 2; 351f10b502Sjtc else if (*s <= 'Z') 361f10b502Sjtc digit = *s - 'A' + 12; 371f10b502Sjtc else 381f10b502Sjtc digit = *s - 'a' + 38; 391f10b502Sjtc 401f10b502Sjtc value |= digit << shift; 411f10b502Sjtc shift += 6; 421f10b502Sjtc } 431f10b502Sjtc 441f10b502Sjtc return (long) value; 451f10b502Sjtc } 46