diff options
Diffstat (limited to 'src/lib/libc/stdlib/a64l.c')
-rw-r--r-- | src/lib/libc/stdlib/a64l.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/lib/libc/stdlib/a64l.c b/src/lib/libc/stdlib/a64l.c index 03fc77e034..5312929c6f 100644 --- a/src/lib/libc/stdlib/a64l.c +++ b/src/lib/libc/stdlib/a64l.c | |||
@@ -1,34 +1,42 @@ | |||
1 | /* $OpenBSD: a64l.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */ | ||
1 | /* | 2 | /* |
2 | * Written by J.T. Conklin <jtc@netbsd.org>. | 3 | * Written by J.T. Conklin <jtc@netbsd.org>. |
3 | * Public domain. | 4 | * Public domain. |
4 | */ | 5 | */ |
5 | 6 | ||
6 | #if defined(LIBC_SCCS) && !defined(lint) | 7 | #include <errno.h> |
7 | static char *rcsid = "$NetBSD: a64l.c,v 1.3 1995/05/11 23:04:47 jtc Exp $"; | 8 | #include <stdlib.h> |
8 | #endif | ||
9 | 9 | ||
10 | long | 10 | long |
11 | a64l(s) | 11 | a64l(const char *s) |
12 | const char *s; | ||
13 | { | 12 | { |
14 | long value, digit, shift; | 13 | long value, digit, shift; |
15 | int i; | 14 | int i; |
16 | 15 | ||
16 | if (s == NULL) { | ||
17 | errno = EINVAL; | ||
18 | return(-1L); | ||
19 | } | ||
20 | |||
17 | value = 0; | 21 | value = 0; |
18 | shift = 0; | 22 | shift = 0; |
19 | for (i = 0; *s && i < 6; i++, s++) { | 23 | for (i = 0; *s && i < 6; i++, s++) { |
20 | if (*s <= '/') | 24 | if (*s >= '.' && *s <= '/') |
21 | digit = *s - '.'; | 25 | digit = *s - '.'; |
22 | else if (*s <= '9') | 26 | else if (*s >= '0' && *s <= '9') |
23 | digit = *s - '0' + 2; | 27 | digit = *s - '0' + 2; |
24 | else if (*s <= 'Z') | 28 | else if (*s >= 'A' && *s <= 'Z') |
25 | digit = *s - 'A' + 12; | 29 | digit = *s - 'A' + 12; |
26 | else | 30 | else if (*s >= 'a' && *s <= 'z') |
27 | digit = *s - 'a' + 38; | 31 | digit = *s - 'a' + 38; |
32 | else { | ||
33 | errno = EINVAL; | ||
34 | return(-1L); | ||
35 | } | ||
28 | 36 | ||
29 | value |= digit << shift; | 37 | value |= digit << shift; |
30 | shift += 6; | 38 | shift += 6; |
31 | } | 39 | } |
32 | 40 | ||
33 | return (long) value; | 41 | return(value); |
34 | } | 42 | } |