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.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/lib/libc/stdlib/a64l.c b/src/lib/libc/stdlib/a64l.c
index 03fc77e034..518bdb64f9 100644
--- a/src/lib/libc/stdlib/a64l.c
+++ b/src/lib/libc/stdlib/a64l.c
@@ -4,31 +4,42 @@
4 */ 4 */
5 5
6#if defined(LIBC_SCCS) && !defined(lint) 6#if defined(LIBC_SCCS) && !defined(lint)
7static char *rcsid = "$NetBSD: a64l.c,v 1.3 1995/05/11 23:04:47 jtc Exp $"; 7static char *rcsid = "$OpenBSD: a64l.c,v 1.4 2005/03/30 18:51:49 pat Exp $";
8#endif 8#endif /* LIBC_SCCS and not lint */
9
10#include <errno.h>
11#include <stdlib.h>
9 12
10long 13long
11a64l(s) 14a64l(const char *s)
12 const char *s;
13{ 15{
14 long value, digit, shift; 16 long value, digit, shift;
15 int i; 17 int i;
16 18
19 if (s == NULL) {
20 errno = EINVAL;
21 return(-1L);
22 }
23
17 value = 0; 24 value = 0;
18 shift = 0; 25 shift = 0;
19 for (i = 0; *s && i < 6; i++, s++) { 26 for (i = 0; *s && i < 6; i++, s++) {
20 if (*s <= '/') 27 if (*s >= '.' && *s <= '/')
21 digit = *s - '.'; 28 digit = *s - '.';
22 else if (*s <= '9') 29 else if (*s >= '0' && *s <= '9')
23 digit = *s - '0' + 2; 30 digit = *s - '0' + 2;
24 else if (*s <= 'Z') 31 else if (*s >= 'A' && *s <= 'Z')
25 digit = *s - 'A' + 12; 32 digit = *s - 'A' + 12;
26 else 33 else if (*s >= 'a' && *s <= 'z')
27 digit = *s - 'a' + 38; 34 digit = *s - 'a' + 38;
35 else {
36 errno = EINVAL;
37 return(-1L);
38 }
28 39
29 value |= digit << shift; 40 value |= digit << shift;
30 shift += 6; 41 shift += 6;
31 } 42 }
32 43
33 return (long) value; 44 return(value);
34} 45}