a64l.c revision 1.9
11.1Sjtc/* 21.9Ssalo * Written by J.T. Conklin <jtc@NetBSD.org>. 31.3Sjtc * Public domain. 41.1Sjtc */ 51.1Sjtc 61.4Schristos#include <sys/cdefs.h> 71.1Sjtc#if defined(LIBC_SCCS) && !defined(lint) 81.9Ssalo__RCSID("$NetBSD: a64l.c,v 1.9 2003/07/26 19:24:53 salo Exp $"); 91.1Sjtc#endif 101.4Schristos 111.5Sjtc#include "namespace.h" 121.6Slukem 131.6Slukem#include <assert.h> 141.4Schristos#include <stdlib.h> 151.5Sjtc 161.5Sjtc#ifdef __weak_alias 171.8Smycroft__weak_alias(a64l,_a64l) 181.5Sjtc#endif 191.1Sjtc 201.1Sjtclong 211.1Sjtca64l(s) 221.1Sjtc const char *s; 231.1Sjtc{ 241.1Sjtc long value, digit, shift; 251.1Sjtc int i; 261.6Slukem 271.6Slukem _DIAGASSERT(s != NULL); 281.1Sjtc 291.1Sjtc value = 0; 301.1Sjtc shift = 0; 311.1Sjtc for (i = 0; *s && i < 6; i++, s++) { 321.1Sjtc if (*s <= '/') 331.1Sjtc digit = *s - '.'; 341.1Sjtc else if (*s <= '9') 351.1Sjtc digit = *s - '0' + 2; 361.1Sjtc else if (*s <= 'Z') 371.1Sjtc digit = *s - 'A' + 12; 381.1Sjtc else 391.1Sjtc digit = *s - 'a' + 38; 401.1Sjtc 411.1Sjtc value |= digit << shift; 421.1Sjtc shift += 6; 431.1Sjtc } 441.1Sjtc 451.1Sjtc return (long) value; 461.1Sjtc} 47