2012-03-14 01:13:30 +04:00
|
|
|
/* $NetBSD: l64a.c,v 1.14 2012/03/13 21:13:48 christos Exp $ */
|
1999-02-06 18:04:05 +03:00
|
|
|
|
1993-10-22 20:26:43 +03:00
|
|
|
/*
|
2003-07-26 23:24:24 +04:00
|
|
|
* Written by J.T. Conklin <jtc@NetBSD.org>.
|
1995-05-12 03:03:44 +04:00
|
|
|
* Public domain.
|
1993-10-22 20:26:43 +03:00
|
|
|
*/
|
|
|
|
|
1997-07-14 00:16:31 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-10-22 20:26:43 +03:00
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
2012-03-14 01:13:30 +04:00
|
|
|
__RCSID("$NetBSD: l64a.c,v 1.14 2012/03/13 21:13:48 christos Exp $");
|
1993-10-22 20:26:43 +03:00
|
|
|
#endif
|
|
|
|
|
1997-07-21 18:06:24 +04:00
|
|
|
#include "namespace.h"
|
1999-09-16 15:44:54 +04:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
1993-10-22 20:26:43 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
1997-07-21 18:06:24 +04:00
|
|
|
#ifdef __weak_alias
|
2000-01-23 01:19:07 +03:00
|
|
|
__weak_alias(l64a,_l64a)
|
|
|
|
__weak_alias(l64a_r,_l64a_r)
|
1997-07-21 18:06:24 +04:00
|
|
|
#endif
|
|
|
|
|
1993-10-22 20:26:43 +03:00
|
|
|
char *
|
2012-03-14 01:13:30 +04:00
|
|
|
l64a(long value)
|
1993-10-22 20:26:43 +03:00
|
|
|
{
|
|
|
|
static char buf[8];
|
1999-02-06 18:04:05 +03:00
|
|
|
|
2012-03-14 01:13:30 +04:00
|
|
|
(void)l64a_r(value, buf, (int)sizeof (buf));
|
1999-02-06 18:04:05 +03:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-14 01:13:30 +04:00
|
|
|
l64a_r(long value, char *buffer, int buflen)
|
1999-02-06 18:04:05 +03:00
|
|
|
{
|
|
|
|
char *s = buffer;
|
1993-10-22 20:26:43 +03:00
|
|
|
int digit;
|
1998-11-15 20:13:51 +03:00
|
|
|
unsigned long v = value;
|
1993-10-22 20:26:43 +03:00
|
|
|
|
1999-09-16 15:44:54 +04:00
|
|
|
_DIAGASSERT(buffer != NULL);
|
|
|
|
|
1999-02-06 18:04:05 +03:00
|
|
|
if (value == 0UL)
|
1998-06-14 21:28:15 +04:00
|
|
|
goto out;
|
1993-10-22 20:26:43 +03:00
|
|
|
|
1999-02-06 18:04:05 +03:00
|
|
|
for (; v != 0 && buflen > 1; s++, buflen--) {
|
1998-11-15 20:13:51 +03:00
|
|
|
digit = (int)(v & 0x3f);
|
1993-10-22 20:26:43 +03:00
|
|
|
|
|
|
|
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;
|
1998-11-15 20:13:51 +03:00
|
|
|
v >>= 6;
|
1993-10-22 20:26:43 +03:00
|
|
|
}
|
|
|
|
|
1998-06-14 21:28:15 +04:00
|
|
|
out:
|
1993-10-22 20:26:43 +03:00
|
|
|
*s = '\0';
|
|
|
|
|
1999-02-06 18:04:05 +03:00
|
|
|
return (v == 0UL ? 0 : -1);
|
1993-10-22 20:26:43 +03:00
|
|
|
}
|