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