summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/l64a.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/l64a.c')
-rw-r--r--src/lib/libc/stdlib/l64a.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/lib/libc/stdlib/l64a.c b/src/lib/libc/stdlib/l64a.c
new file mode 100644
index 0000000000..325b41b33b
--- /dev/null
+++ b/src/lib/libc/stdlib/l64a.c
@@ -0,0 +1,45 @@
1/*
2 * Written by J.T. Conklin <jtc@netbsd.org>.
3 * Public domain.
4 */
5
6#if defined(LIBC_SCCS) && !defined(lint)
7static char *rcsid = "$OpenBSD: l64a.c,v 1.4 2005/03/30 18:51:49 pat Exp $";
8#endif /* LIBC_SCCS and not lint */
9
10#include <errno.h>
11#include <stdlib.h>
12
13char *
14l64a(long value)
15{
16 static char buf[8];
17 char *s = buf;
18 int digit;
19 int i;
20
21 if (value < 0) {
22 errno = EINVAL;
23 return(NULL);
24 }
25
26 for (i = 0; value != 0 && i < 6; i++) {
27 digit = value & 0x3f;
28
29 if (digit < 2)
30 *s = digit + '.';
31 else if (digit < 12)
32 *s = digit + '0' - 2;
33 else if (digit < 38)
34 *s = digit + 'A' - 12;
35 else
36 *s = digit + 'a' - 38;
37
38 value >>= 6;
39 s++;
40 }
41
42 *s = '\0';
43
44 return(buf);
45}