]>
Commit | Line | Data |
---|---|---|
5b2abdfb A |
1 | /* |
2 | * Written by J.T. Conklin <jtc@netbsd.org>. | |
3 | * Public domain. | |
4 | */ | |
5 | ||
6 | #if defined(LIBC_SCCS) && !defined(lint) | |
7 | static char *rcsid = "$OpenBSD: l64a.c,v 1.3 1997/08/17 22:58:34 millert Exp $"; | |
8 | #endif /* LIBC_SCCS and not lint */ | |
9 | ||
10 | #include <errno.h> | |
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 < 0) { | |
23 | errno = EINVAL; | |
24 | return(NULL); | |
25 | } | |
26 | ||
27 | for (i = 0; value != 0 && i < 6; i++) { | |
28 | digit = value & 0x3f; | |
29 | ||
30 | if (digit < 2) | |
31 | *s = digit + '.'; | |
32 | else if (digit < 12) | |
33 | *s = digit + '0' - 2; | |
34 | else if (digit < 38) | |
35 | *s = digit + 'A' - 12; | |
36 | else | |
37 | *s = digit + 'a' - 38; | |
38 | ||
39 | value >>= 6; | |
40 | s++; | |
41 | } | |
42 | ||
43 | *s = '\0'; | |
44 | ||
45 | return(buf); | |
46 | } | |
47 |