summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/a64l.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/a64l.c')
-rw-r--r--src/lib/libc/stdlib/a64l.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/lib/libc/stdlib/a64l.c b/src/lib/libc/stdlib/a64l.c
new file mode 100644
index 0000000000..518bdb64f9
--- /dev/null
+++ b/src/lib/libc/stdlib/a64l.c
@@ -0,0 +1,45 @@
1/*
2 * Written by J.T. Conklin <jtc@netbsd.org>.
3 * Public domain.
4 */
5
6#if defined(LIBC_SCCS) && !defined(lint)
7static char *rcsid = "$OpenBSD: a64l.c,v 1.4 2005/03/30 18:51:49 pat Exp $";
8#endif /* LIBC_SCCS and not lint */
9
10#include <errno.h>
11#include <stdlib.h>
12
13long
14a64l(const char *s)
15{
16 long value, digit, shift;
17 int i;
18
19 if (s == NULL) {
20 errno = EINVAL;
21 return(-1L);
22 }
23
24 value = 0;
25 shift = 0;
26 for (i = 0; *s && i < 6; i++, s++) {
27 if (*s >= '.' && *s <= '/')
28 digit = *s - '.';
29 else if (*s >= '0' && *s <= '9')
30 digit = *s - '0' + 2;
31 else if (*s >= 'A' && *s <= 'Z')
32 digit = *s - 'A' + 12;
33 else if (*s >= 'a' && *s <= 'z')
34 digit = *s - 'a' + 38;
35 else {
36 errno = EINVAL;
37 return(-1L);
38 }
39
40 value |= digit << shift;
41 shift += 6;
42 }
43
44 return(value);
45}