libutil: add O_NOCTTY back to old pty open code
[minix.git] / lib / libc / stdlib / l64a.c
blob68f6251269930fc89b14e8c16db5cec19233af82
1 /* $NetBSD: l64a.c,v 1.13 2003/07/26 19:24:54 salo Exp $ */
3 /*
4 * Written by J.T. Conklin <jtc@NetBSD.org>.
5 * Public domain.
6 */
8 #include <sys/cdefs.h>
9 #if defined(LIBC_SCCS) && !defined(lint)
10 __RCSID("$NetBSD: l64a.c,v 1.13 2003/07/26 19:24:54 salo Exp $");
11 #endif
13 #include "namespace.h"
15 #include <assert.h>
16 #include <errno.h>
17 #include <stdlib.h>
19 #ifdef __weak_alias
20 __weak_alias(l64a,_l64a)
21 __weak_alias(l64a_r,_l64a_r)
22 #endif
24 char *
25 l64a (value)
26 long value;
28 static char buf[8];
30 (void)l64a_r(value, buf, sizeof (buf));
31 return buf;
34 int
35 l64a_r (value, buffer, buflen)
36 long value;
37 char *buffer;
38 int buflen;
40 char *s = buffer;
41 int digit;
42 unsigned long v = value;
44 _DIAGASSERT(buffer != NULL);
46 if (value == 0UL)
47 goto out;
49 for (; v != 0 && buflen > 1; s++, buflen--) {
50 digit = (int)(v & 0x3f);
52 if (digit < 2)
53 *s = digit + '.';
54 else if (digit < 12)
55 *s = digit + '0' - 2;
56 else if (digit < 38)
57 *s = digit + 'A' - 12;
58 else
59 *s = digit + 'a' - 38;
60 v >>= 6;
63 out:
64 *s = '\0';
66 return (v == 0UL ? 0 : -1);