xref: /netbsd-src/lib/libc/stdlib/l64a.c (revision 1394f01b4a9e99092957ca5d824d67219565d9b5)
1 /*
2  * Written by J.T. Conklin <jtc@netbsd.org>.
3  * Public domain.
4  */
5 
6 #include <sys/cdefs.h>
7 #if defined(LIBC_SCCS) && !defined(lint)
8 __RCSID("$NetBSD: l64a.c,v 1.5 1997/07/13 20:16:44 christos Exp $");
9 #endif
10 
11 #include <stdlib.h>
12 
13 char *
14 l64a (value)
15 	long value;
16 {
17 	static char buf[8];
18 	char *s = buf;
19 	int digit;
20 	int i;
21 
22 	if (!value)
23 		return NULL;
24 
25 	for (i = 0; value != 0 && i < 6; i++) {
26 		digit = value & 0x3f;
27 
28 		if (digit < 2)
29 			*s = digit + '.';
30 		else if (digit < 12)
31 			*s = digit + '0' - 2;
32 		else if (digit < 38)
33 			*s = digit + 'A' - 12;
34 		else
35 			*s = digit + 'a' - 38;
36 
37 		value >>= 6;
38 		s++;
39 	}
40 
41 	*s = '\0';
42 
43 	return buf;
44 }
45