a64l.c revision 1.7
1/*
2 * Written by J.T. Conklin <jtc@netbsd.org>.
3 * Public domain.
4 */
5
6#include <sys/cdefs.h>
7#if defined(LIBC_SCCS) && !defined(lint)
8__RCSID("$NetBSD: a64l.c,v 1.7 1999/09/20 04:39:36 lukem Exp $");
9#endif
10
11#include "namespace.h"
12
13#include <assert.h>
14#include <stdlib.h>
15
16#ifdef __weak_alias
17__weak_alias(a64l,_a64l);
18#endif
19
20long
21a64l(s)
22	const char *s;
23{
24	long value, digit, shift;
25	int i;
26
27	_DIAGASSERT(s != NULL);
28
29	value = 0;
30	shift = 0;
31	for (i = 0; *s && i < 6; i++, s++) {
32		if (*s <= '/')
33			digit = *s - '.';
34		else if (*s <= '9')
35			digit = *s - '0' + 2;
36		else if (*s <= 'Z')
37			digit = *s - 'A' + 12;
38		else
39			digit = *s - 'a' + 38;
40
41		value |= digit << shift;
42		shift += 6;
43	}
44
45	return (long) value;
46}
47