]> git.saurik.com Git - apple/libc.git/blame_incremental - stdlib/l64a.c
Libc-1272.250.1.tar.gz
[apple/libc.git] / stdlib / l64a.c
... / ...
CommitLineData
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.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
13char *
14#ifdef __LP64__
15l64a(v)
16 long v;
17#else /* !__LP64__ */
18l64a(value)
19 long value;
20#endif /* __LP64__ */
21{
22 static char buf[8];
23#ifdef __LP64__
24 int value = v;
25#endif /* __LP64__ */
26 char *s = buf;
27 int digit;
28 int i;
29
30#ifndef __LP64__
31 if (value < 0) {
32 errno = EINVAL;
33 return(NULL);
34 }
35#endif /* __LP64__ */
36
37 for (i = 0; value != 0 && i < 6; i++) {
38 digit = value & 0x3f;
39
40 if (digit < 2)
41 *s = digit + '.';
42 else if (digit < 12)
43 *s = digit + '0' - 2;
44 else if (digit < 38)
45 *s = digit + 'A' - 12;
46 else
47 *s = digit + 'a' - 38;
48
49 value >>= 6;
50 s++;
51 }
52
53 *s = '\0';
54
55 return(buf);
56}
57