a64l.c revision 1.5
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.5Sjtc__RCSID("$NetBSD: a64l.c,v 1.5 1997/07/21 14:08:48 jtc Exp $");
91.1Sjtc#endif
101.4Schristos
111.5Sjtc#include "namespace.h"
121.4Schristos#include <stdlib.h>
131.5Sjtc
141.5Sjtc#ifdef __weak_alias
151.5Sjtc__weak_alias(a64l,_a64l);
161.5Sjtc#endif
171.1Sjtc
181.1Sjtclong
191.1Sjtca64l(s)
201.1Sjtc	const char *s;
211.1Sjtc{
221.1Sjtc	long value, digit, shift;
231.1Sjtc	int i;
241.1Sjtc
251.1Sjtc	value = 0;
261.1Sjtc	shift = 0;
271.1Sjtc	for (i = 0; *s && i < 6; i++, s++) {
281.1Sjtc		if (*s <= '/')
291.1Sjtc			digit = *s - '.';
301.1Sjtc		else if (*s <= '9')
311.1Sjtc			digit = *s - '0' + 2;
321.1Sjtc		else if (*s <= 'Z')
331.1Sjtc			digit = *s - 'A' + 12;
341.1Sjtc		else
351.1Sjtc			digit = *s - 'a' + 38;
361.1Sjtc
371.1Sjtc		value |= digit << shift;
381.1Sjtc		shift += 6;
391.1Sjtc	}
401.1Sjtc
411.1Sjtc	return (long) value;
421.1Sjtc}
43