]>
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 * | |
224c7076 A |
14 | #ifdef __LP64__ |
15 | l64a(v) | |
16 | long v; | |
17 | #else /* !__LP64__ */ | |
5b2abdfb A |
18 | l64a(value) |
19 | long value; | |
224c7076 | 20 | #endif /* __LP64__ */ |
5b2abdfb A |
21 | { |
22 | static char buf[8]; | |
224c7076 A |
23 | #ifdef __LP64__ |
24 | int value = v; | |
25 | #endif /* __LP64__ */ | |
5b2abdfb A |
26 | char *s = buf; |
27 | int digit; | |
28 | int i; | |
29 | ||
224c7076 | 30 | #ifndef __LP64__ |
5b2abdfb A |
31 | if (value < 0) { |
32 | errno = EINVAL; | |
33 | return(NULL); | |
34 | } | |
224c7076 | 35 | #endif /* __LP64__ */ |
5b2abdfb A |
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 |