a64l.c revision 1.6
11.1Sjtc/*
21.3Sjtc * 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.6Slukem__RCSID("$NetBSD: a64l.c,v 1.6 1999/09/16 11:45:33 lukem 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.5Sjtc__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.6Slukem#ifdef _DIAGNOSTIC
291.6Slukem	if (s == NULL)
301.6Slukem		return (0L);
311.6Slukem#endif
321.1Sjtc
331.1Sjtc	value = 0;
341.1Sjtc	shift = 0;
351.1Sjtc	for (i = 0; *s && i < 6; i++, s++) {
361.1Sjtc		if (*s <= '/')
371.1Sjtc			digit = *s - '.';
381.1Sjtc		else if (*s <= '9')
391.1Sjtc			digit = *s - '0' + 2;
401.1Sjtc		else if (*s <= 'Z')
411.1Sjtc			digit = *s - 'A' + 12;
421.1Sjtc		else
431.1Sjtc			digit = *s - 'a' + 38;
441.1Sjtc
451.1Sjtc		value |= digit << shift;
461.1Sjtc		shift += 6;
471.1Sjtc	}
481.1Sjtc
491.1Sjtc	return (long) value;
501.1Sjtc}
51