1/*
2 * Written by J.T. Conklin <jtc@NetBSD.org>.
3 * Public domain.
4 */
5
6#if 0
7#if defined(LIBC_SCCS) && !defined(lint)
8__RCSID("$NetBSD: l64a.c,v 1.13 2003/07/26 19:24:54 salo Exp $");
9#endif /* not lint */
10#endif
11
12#include <sys/cdefs.h>
13__FBSDID("$FreeBSD$");
14
15#include <stdint.h>
16#include <stdlib.h>
17
18char *
19l64a(long value)
20{
21	static char buf[7];
22
23	(void)l64a_r(value, buf, sizeof(buf));
24	return (buf);
25}
26
27int
28l64a_r(long value, char *buffer, int buflen)
29{
30	static const char chars[] =
31	    "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
32	uint32_t v;
33
34	v = value;
35	while (buflen-- > 0) {
36		if (v == 0) {
37			*buffer = '\0';
38			return (0);
39		}
40		*buffer++ = chars[v & 0x3f];
41		v >>= 6;
42	}
43	return (-1);
44}
45