Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/lib/libc/stdlib/l64a.c
178424 views
1
/*
2
* Written by J.T. Conklin <[email protected]>.
3
* Public domain.
4
*/
5
6
#if 0
7
#if defined(LIBC_SCCS) && !defined(lint)
8
__RCSID("$NetBSD: l64a.c,v 1.13 2003/07/26 19:24:54 salo Exp $");
9
#endif /* not lint */
10
#endif
11
12
#include <sys/cdefs.h>
13
#include <stdint.h>
14
#include <stdlib.h>
15
16
char *
17
l64a(long value)
18
{
19
static char buf[7];
20
21
(void)l64a_r(value, buf, sizeof(buf));
22
return (buf);
23
}
24
25
int
26
l64a_r(long value, char *buffer, int buflen)
27
{
28
static const char chars[] =
29
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
30
uint32_t v;
31
32
v = value;
33
while (buflen-- > 0) {
34
if (v == 0) {
35
*buffer = '\0';
36
return (0);
37
}
38
*buffer++ = chars[v & 0x3f];
39
v >>= 6;
40
}
41
return (-1);
42
}
43
44