]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Written by J.T. Conklin <jtc@netbsd.org>. | |
3 | * Public domain. | |
4 | */ | |
5 | ||
6 | #if defined(LIBC_SCCS) && !defined(lint) | |
7 | static char *rcsid = "$OpenBSD: a64l.c,v 1.3 1997/08/17 22:58:34 millert Exp $"; | |
8 | #endif /* LIBC_SCCS and not lint */ | |
9 | ||
10 | #include <errno.h> | |
11 | #include <stdlib.h> | |
12 | ||
13 | long | |
14 | a64l(s) | |
15 | const char *s; | |
16 | { | |
17 | int value, digit, shift; | |
18 | int i; | |
19 | ||
20 | if (s == NULL) { | |
21 | errno = EINVAL; | |
22 | return(-1L); | |
23 | } | |
24 | ||
25 | value = 0; | |
26 | shift = 0; | |
27 | for (i = 0; *s && i < 6; i++, s++) { | |
28 | if (*s >= '.' && *s <= '/') | |
29 | digit = *s - '.'; | |
30 | else if (*s >= '0' && *s <= '9') | |
31 | digit = *s - '0' + 2; | |
32 | else if (*s >= 'A' && *s <= 'Z') | |
33 | digit = *s - 'A' + 12; | |
34 | else if (*s >= 'a' && *s <= 'z') | |
35 | digit = *s - 'a' + 38; | |
36 | else { | |
37 | errno = EINVAL; | |
38 | return(-1L); | |
39 | } | |
40 | ||
41 | value |= digit << shift; | |
42 | shift += 6; | |
43 | } | |
44 | ||
45 | return(value); | |
46 | } | |
47 |