diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-08-17 22:58:35 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-08-17 22:58:35 +0000 |
commit | 60bc132b385fbae6257c2da60bf75f22933de26d (patch) | |
tree | 41396498051c1448ff13ebbdff662e2f88927f51 /lib/libc/stdlib/a64l.c | |
parent | 581c9d45f651d2c40755c920da5dc637753a7734 (diff) |
Man page for a64l(3) and l64a(3), based on a64l.3 from the MiNT docs 0.1.
Also make a64l(3) and l64a(3) deal reasonably with inapropriate
input. The standard does not require this, but it does not disallow
it either.
Diffstat (limited to 'lib/libc/stdlib/a64l.c')
-rw-r--r-- | lib/libc/stdlib/a64l.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/libc/stdlib/a64l.c b/lib/libc/stdlib/a64l.c index 975e26ebb20..a68f0a6dcd8 100644 --- a/lib/libc/stdlib/a64l.c +++ b/lib/libc/stdlib/a64l.c @@ -4,9 +4,12 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: a64l.c,v 1.2 1996/08/19 08:33:19 tholo Exp $"; +static char *rcsid = "$OpenBSD: a64l.c,v 1.3 1997/08/17 22:58:34 millert Exp $"; #endif /* LIBC_SCCS and not lint */ +#include <errno.h> +#include <stdlib.h> + long a64l(s) const char *s; @@ -14,21 +17,30 @@ a64l(s) long value, digit, shift; int i; + if (s == NULL) { + errno = EINVAL; + return(-1L); + } + value = 0; shift = 0; for (i = 0; *s && i < 6; i++, s++) { - if (*s <= '/') + if (*s >= '.' && *s <= '/') digit = *s - '.'; - else if (*s <= '9') + else if (*s >= '0' && *s <= '9') digit = *s - '0' + 2; - else if (*s <= 'Z') + else if (*s >= 'A' && *s <= 'Z') digit = *s - 'A' + 12; - else - digit = *s - 'a' + 38; + else if (*s >= 'a' && *s <= 'z') + digit = *s - 'a' + 38; + else { + errno = EINVAL; + return(-1L); + } value |= digit << shift; shift += 6; } - return (long) value; + return(value); } |