From 8190ceb049ac4ab6148966f67d239e0618b7114b Mon Sep 17 00:00:00 2001 From: trhodes Date: Sat, 24 Dec 2005 22:37:59 +0000 Subject: Add a64l(), l64a(), and l64a_r() XSI extentions. These functions convert between a 32-bit integer and a radix-64 ASCII string. The l64a_r() function is a NetBSD addition. PR: 51209 (based on submission, but very different) Reviewed by: bde, ru --- lib/libc/stdlib/a64l.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/libc/stdlib/a64l.c (limited to 'lib/libc/stdlib/a64l.c') diff --git a/lib/libc/stdlib/a64l.c b/lib/libc/stdlib/a64l.c new file mode 100644 index 0000000..6d175ef --- /dev/null +++ b/lib/libc/stdlib/a64l.c @@ -0,0 +1,46 @@ +/*- + * Written by J.T. Conklin . + * Public domain. + */ + +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: a64l.c,v 1.8 2000/01/22 22:19:19 mycroft Exp $"); +#endif /* not lint */ +#endif + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +#define ADOT 46 /* ASCII '.' */ +#define ASLASH ADOT + 1 /* ASCII '/' */ +#define A0 48 /* ASCII '0' */ +#define AA 65 /* ASCII 'A' */ +#define Aa 97 /* ASCII 'a' */ + +long +a64l(const char *s) +{ + long shift; + int digit, i, value; + + value = 0; + shift = 0; + for (i = 0; *s != '\0' && i < 6; i++, s++) { + if (*s <= ASLASH) + digit = *s - ASLASH + 1; + else if (*s <= A0 + 9) + digit = *s - A0 + 2; + else if (*s <= AA + 25) + digit = *s - AA + 12; + else + digit = *s - Aa + 38; + + value |= digit << shift; + shift += 6; + } + return (value); +} -- cgit v1.1