a64l.c revision 1.10
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.10Sabs__RCSID("$NetBSD: a64l.c,v 1.10 2012/06/08 11:15:26 abs 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.10Sabsa64l(const char *s)
221.1Sjtc{
231.1Sjtc	long value, digit, shift;
241.1Sjtc	int i;
251.6Slukem
261.6Slukem	_DIAGASSERT(s != NULL);
271.1Sjtc
281.1Sjtc	value = 0;
291.1Sjtc	shift = 0;
301.1Sjtc	for (i = 0; *s && i < 6; i++, s++) {
311.1Sjtc		if (*s <= '/')
321.1Sjtc			digit = *s - '.';
331.1Sjtc		else if (*s <= '9')
341.1Sjtc			digit = *s - '0' + 2;
351.1Sjtc		else if (*s <= 'Z')
361.1Sjtc			digit = *s - 'A' + 12;
371.1Sjtc		else
381.1Sjtc			digit = *s - 'a' + 38;
391.1Sjtc
401.1Sjtc		value |= digit << shift;
411.1Sjtc		shift += 6;
421.1Sjtc	}
431.1Sjtc
441.1Sjtc	return (long) value;
451.1Sjtc}
46