summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorkleink <kleink@NetBSD.org>1999-02-06 15:04:05 +0000
committerkleink <kleink@NetBSD.org>1999-02-06 15:04:05 +0000
commite2b924d2ae9fd221f0221dc525c1e030e7d4938a (patch)
tree60f8505fafaf8a87dcb02ba478cb986c9679ecad /lib/libc/stdlib
parentca03c2d3eff66c136a07a480619efe473691101c (diff)
Add l64a_r(), a reentrant version of l64a(); found in the Multithreading
Extension of SVID4.
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/Makefile.inc3
-rw-r--r--lib/libc/stdlib/a64l.343
-rw-r--r--lib/libc/stdlib/l64a.c26
3 files changed, 59 insertions, 13 deletions
diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc
index b520f5f2049..200124cbca0 100644
--- a/lib/libc/stdlib/Makefile.inc
+++ b/lib/libc/stdlib/Makefile.inc
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.38 1998/06/14 17:49:21 kleink Exp $
+# $NetBSD: Makefile.inc,v 1.39 1999/02/06 15:04:05 kleink Exp $
# from: @(#)Makefile.inc 8.3 (Berkeley) 2/4/95
# stdlib sources
@@ -25,6 +25,7 @@ MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \
strtol.3 strtoul.3 system.3
MLINKS+=a64l.3 l64a.3
+MLINKS+=a64l.3 l64a_r.3
MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3
MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3
MLINKS+=rand.3 rand_r.3
diff --git a/lib/libc/stdlib/a64l.3 b/lib/libc/stdlib/a64l.3
index 2bf8ce545be..50886e3457a 100644
--- a/lib/libc/stdlib/a64l.3
+++ b/lib/libc/stdlib/a64l.3
@@ -1,6 +1,6 @@
-.\" $NetBSD: a64l.3,v 1.2 1998/06/14 17:54:59 kleink Exp $
+.\" $NetBSD: a64l.3,v 1.3 1999/02/06 15:04:05 kleink Exp $
.\"
-.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
+.\" Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
@@ -34,12 +34,13 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd June 14, 1998
+.Dd February 6, 1999
.Dt A64L 3
.Os NetBSD 1.0
.Sh NAME
.Nm a64l ,
-.Nm l64a
+.Nm l64a ,
+.Nm l64a_r
.Nd convert between a long integer and a base-64 ASCII string
.Sh LIBRARY
.Lb libc
@@ -48,7 +49,9 @@
.Ft long
.Fn a64l "const char *s"
.Ft char *
-.Fn l64a "long l"
+.Fn l64a "long int l"
+.Ft int
+.Fn l64a_r "long int l" "char *buffer" "int buflen"
.Sh DESCRIPTION
The
.Fn a64l
@@ -75,6 +78,15 @@ takes a long integer value,
.Fa l ,
and returns a pointer to the corresponding NUL-terminated base-64
ASCII string representation.
+.Pp
+.Fn l64a_r
+performs a conversion identical to that of
+.Fn l64a
+and stores the resulting representation in the memory area pointed to by
+.Fa buffer ,
+consuming at most
+.Fa buflen
+characters including the terminating NUL character.
.Sh RETURN VALUES
On successful completion,
.Fn a64l
@@ -93,8 +105,26 @@ If
is 0L,
.Fn l64a
returns a pointer to an empty string.
+.Pp
+On successful completion,
+.Fn l64a_r
+returns 0; if
+.Fa buffer
+is of insufficient length, -1 is returned.
.Sh SEE ALSO
.Xr strtol 3
+.Sh STANDARDS
+The
+.Fn a64l
+and
+.Fn l64a
+functions conform to
+.St -xpg4.2 .
+The
+.Fn l64a_r
+function conforms to
+.St -svid4 ,
+Multithreading Extension.
.Sh BUGS
The
.Fn l64a
@@ -102,3 +132,6 @@ function is not reentrant. The value returned by it points into a
static buffer area; subsequent calls to
.Fn la64a
may overwrite this buffer.
+In multi-threaded applications,
+.Fn l64a_r
+should be used instead.
diff --git a/lib/libc/stdlib/l64a.c b/lib/libc/stdlib/l64a.c
index 44153ac35cd..cc7eaf94990 100644
--- a/lib/libc/stdlib/l64a.c
+++ b/lib/libc/stdlib/l64a.c
@@ -1,3 +1,5 @@
+/* $NetBSD: l64a.c,v 1.9 1999/02/06 15:04:05 kleink Exp $ */
+
/*
* Written by J.T. Conklin <jtc@netbsd.org>.
* Public domain.
@@ -5,7 +7,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: l64a.c,v 1.8 1998/11/15 17:13:51 christos Exp $");
+__RCSID("$NetBSD: l64a.c,v 1.9 1999/02/06 15:04:05 kleink Exp $");
#endif
#include "namespace.h"
@@ -13,6 +15,7 @@ __RCSID("$NetBSD: l64a.c,v 1.8 1998/11/15 17:13:51 christos Exp $");
#ifdef __weak_alias
__weak_alias(l64a,_l64a);
+__weak_alias(l64a_r,_l64a_r);
#endif
char *
@@ -20,15 +23,25 @@ l64a (value)
long value;
{
static char buf[8];
- char *s = buf;
+
+ (void)l64a_r(value, buf, sizeof (buf));
+ return buf;
+}
+
+int
+l64a_r (value, buffer, buflen)
+ long value;
+ char *buffer;
+ int buflen;
+{
+ char *s = buffer;
int digit;
- int i;
unsigned long v = value;
- if (!value)
+ if (value == 0UL)
goto out;
- for (i = 0; v != 0 && i < 6; i++) {
+ for (; v != 0 && buflen > 1; s++, buflen--) {
digit = (int)(v & 0x3f);
if (digit < 2)
@@ -40,11 +53,10 @@ l64a (value)
else
*s = digit + 'a' - 38;
v >>= 6;
- s++;
}
out:
*s = '\0';
- return buf;
+ return (v == 0UL ? 0 : -1);
}