View | Details | Raw Unified | Return to bug 51209
Collapse All | Expand All

(-)src/lib/libc/stdlib/Makefile.inc (-11 / +13 lines)
Lines 4-29 Link Here
4
# machine-independent stdlib sources
4
# machine-independent stdlib sources
5
.PATH: ${.CURDIR}/${MACHINE_ARCH}/stdlib ${.CURDIR}/stdlib
5
.PATH: ${.CURDIR}/${MACHINE_ARCH}/stdlib ${.CURDIR}/stdlib
6
6
7
MISRCS+=_Exit.c abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c \
7
MISRCS+=_Exit.c a64l.c abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c \
8
	bsearch.c calloc.c div.c exit.c getenv.c getopt.c getopt_long.c \
8
	bsearch.c calloc.c div.c exit.c getenv.c getopt.c getopt_long.c \
9
	getsubopt.c grantpt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c \
9
	getsubopt.c grantpt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c \
10
	insque.c labs.c ldiv.c llabs.c lldiv.c lsearch.c malloc.c merge.c \
10
	insque.c l64a.c labs.c ldiv.c llabs.c lldiv.c lsearch.c malloc.c \
11
	putenv.c qsort.c qsort_r.c radixsort.c rand.c random.c reallocf.c \
11
	merge.c putenv.c qsort.c qsort_r.c radixsort.c rand.c random.c \
12
	realpath.c remque.c setenv.c strfmon.c strhash.c strtoimax.c \
12
	reallocf.c realpath.c remque.c setenv.c strfmon.c strhash.c \
13
	strtol.c strtoll.c strtoq.c strtoul.c strtoull.c strtoumax.c strtouq.c \
13
	strtoimax.c strtol.c strtoll.c strtoq.c strtoul.c strtoull.c \
14
	system.c tdelete.c tfind.c tsearch.c twalk.c
14
	strtoumax.c strtouq.c system.c tdelete.c tfind.c tsearch.c twalk.c
15
15
16
# machine-dependent stdlib sources
16
# machine-dependent stdlib sources
17
.if exists(${.CURDIR}/${MACHINE_ARCH}/stdlib/Makefile.inc)
17
.if exists(${.CURDIR}/${MACHINE_ARCH}/stdlib/Makefile.inc)
18
.include "${.CURDIR}/${MACHINE_ARCH}/stdlib/Makefile.inc"
18
.include "${.CURDIR}/${MACHINE_ARCH}/stdlib/Makefile.inc"
19
.endif
19
.endif
20
20
21
MAN+=	abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \
21
MAN+=	a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 \
22
	div.3 exit.3 getenv.3 getopt.3 getopt_long.3 getsubopt.3 grantpt.3 \
22
	bsearch.3 div.3 exit.3 getenv.3 getopt.3 getopt_long.3 \
23
	hcreate.3 imaxabs.3 imaxdiv.3 insque.3 labs.3 ldiv.3 llabs.3 lldiv.3 \
23
	getsubopt.3 grantpt.3 hcreate.3 imaxabs.3 imaxdiv.3 insque.3 \
24
	lsearch.3 malloc.3 memory.3 qsort.3 radixsort.3 rand.3 random.3 \
24
	labs.3 ldiv.3 llabs.3 lldiv.3 lsearch.3 malloc.3 memory.3 qsort.3 \
25
	realpath.3 strfmon.3 strtod.3 strtol.3 strtoul.3 system.3 tsearch.3
25
	radixsort.3 rand.3 random.3 realpath.3 strfmon.3 strtod.3 strtol.3 \
26
	strtoul.3 system.3 tsearch.3
26
27
28
MLINKS+=a64l.3 l64a.3 l64a_r.3
27
MLINKS+=atol.3 atoll.3
29
MLINKS+=atol.3 atoll.3
28
MLINKS+=exit.3 _Exit.3
30
MLINKS+=exit.3 _Exit.3
29
MLINKS+=getenv.3 putenv.3 getenv.3 setenv.3 getenv.3 unsetenv.3
31
MLINKS+=getenv.3 putenv.3 getenv.3 setenv.3 getenv.3 unsetenv.3
(-)src/lib/libc/stdlib/a64l.3 (+140 lines)
Added Link Here
1
.\" $NetBSD: a64l.3,v 1.8 2003/04/16 13:34:45 wiz Exp $
2
.\"
3
.\" Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
4
.\" All rights reserved.
5
.\"
6
.\" This code is derived from software contributed to The NetBSD Foundation
7
.\" by Klaus Klein.
8
.\"
9
.\" Redistribution and use in source and binary forms, with or without
10
.\" modification, are permitted provided that the following conditions
11
.\" are met:
12
.\" 1. Redistributions of source code must retain the above copyright
13
.\"    notice, this list of conditions and the following disclaimer.
14
.\" 2. Redistributions in binary form must reproduce the above copyright
15
.\"    notice, this list of conditions and the following disclaimer in the
16
.\"    documentation and/or other materials provided with the distribution.
17
.\" 3. All advertising materials mentioning features or use of this software
18
.\"    must display the following acknowledgement:
19
.\"        This product includes software developed by the NetBSD
20
.\"        Foundation, Inc. and its contributors.
21
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22
.\"    contributors may be used to endorse or promote products derived
23
.\"    from this software without specific prior written permission.
24
.\"
25
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
.\" POSSIBILITY OF SUCH DAMAGE.
36
.\"
37
.\" $FreeBSD$
38
.\"
39
.Dd April 21, 2003
40
.Dt A64L 3
41
.Os
42
.Sh NAME
43
.Nm a64l ,
44
.Nm l64a ,
45
.Nm l64a_r
46
.Nd "convert between a long integer and a base-64 ASCII string"
47
.Sh LIBRARY
48
.Lb libc
49
.Sh SYNOPSIS
50
.In stdlib.h
51
.Ft long
52
.Fn a64l "const char *s"
53
.Ft char *
54
.Fn l64a "long int l"
55
.Ft int
56
.Fn l64a_r "long int l" "char *buffer" "int buflen"
57
.Sh DESCRIPTION
58
The
59
.Fn a64l
60
and
61
.Fn l64a
62
functions convert between a long integer and its base-64 ASCII string
63
representation.
64
.Pp
65
The characters used to represent ``digits'' are
66
`.' for 0,
67
`/' for 1,
68
`0' - `9' for 2 - 11,
69
`A' - `Z' for 12 - 37, and
70
`a' - `z' for 38 - 63.
71
.Pp
72
.Fn a64l
73
takes a pointer to a NUL-terminated base-64 ASCII string
74
representation,
75
.Fa s ,
76
and returns the corresponding long integer value.
77
.Pp
78
.Fn l64a
79
takes a long integer value,
80
.Fa l ,
81
and returns a pointer to the corresponding NUL-terminated base-64
82
ASCII string representation.
83
.Pp
84
.Fn l64a_r
85
performs a conversion identical to that of
86
.Fn l64a
87
and stores the resulting representation in the memory area pointed to by
88
.Fa buffer ,
89
consuming at most
90
.Fa buflen
91
characters including the terminating NUL character.
92
.Sh RETURN VALUES
93
On successful completion,
94
.Fn a64l
95
returns the long integer value corresponding to the input string.
96
If the string pointed to by
97
.Fa s
98
is an empty string,
99
.Fn a64l
100
returns a value of 0L.
101
.Pp
102
.Fn l64a
103
returns a pointer to the base-64 ASCII string representation corresponding to
104
the input value.
105
If
106
.Fa l
107
is 0L,
108
.Fn l64a
109
returns a pointer to an empty string.
110
.Pp
111
On successful completion,
112
.Fn l64a_r
113
returns 0; if
114
.Fa buffer
115
is of insufficient length, -1 is returned.
116
.Sh SEE ALSO
117
.Xr strtol 3
118
.Sh STANDARDS
119
The
120
.Fn a64l
121
and
122
.Fn l64a
123
functions conform to
124
.St -xpg4.2 .
125
The
126
.Fn l64a_r
127
function conforms to
128
.St -svid4 ,
129
Multithreading Extension.
130
.Sh BUGS
131
The
132
.Fn l64a
133
function is not reentrant.
134
The value returned by it points into a static buffer area;
135
subsequent calls to
136
.Fn la64a
137
may overwrite this buffer.
138
In multi-threaded applications,
139
.Fn l64a_r
140
should be used instead.
(-)src/lib/libc/stdlib/a64l.c (+48 lines)
Added Link Here
1
/*
2
 * Written by J.T. Conklin <jtc@netbsd.org>.
3
 * Public domain.
4
 */
5
6
#include <sys/cdefs.h>
7
#if defined(LIBC_SCCS) && !defined(lint)
8
__RCSID("$NetBSD: a64l.c,v 1.8 2000/01/22 22:19:19 mycroft Exp $");
9
#endif /* LIBC_SCCS and not lint */
10
__FBSDID("$FreeBSD$");
11
12
#include "namespace.h"
13
14
#include <assert.h>
15
#include <limits.h>
16
#include <ctype.h>
17
#include <stdlib.h>
18
19
#ifndef _DIAGASSERT
20
#define _DIAGASSERT(X)
21
#endif
22
23
long
24
a64l(const char *s)
25
{
26
	long value, digit, shift;
27
	int i;
28
29
	_DIAGASSERT(s != NULL);
30
31
	value = 0;
32
	shift = 0;
33
	for (i = 0; *s && i < 6; i++, s++) {
34
		if (*s <= '/')
35
			digit = *s - '.';
36
		else if (*s <= '9')
37
			digit = *s - '0' + 2;
38
		else if (*s <= 'Z')
39
			digit = *s - 'A' + 12;
40
		else
41
			digit = *s - 'a' + 38; 
42
43
		value |= digit << shift;
44
		shift += 6;
45
	}
46
47
	return (value);
48
}
(-)src/lib/libc/stdlib/l64a.c (+61 lines)
Added Link Here
1
/*
2
 * Written by J.T. Conklin <jtc@netbsd.org>.
3
 * Public domain.
4
 */
5
6
#include <sys/cdefs.h>
7
#if defined(LIBC_SCCS) && !defined(lint)
8
__RCSID("$NetBSD: l64a.c,v 1.12 2000/01/22 22:19:19 mycroft Exp $");
9
#endif /* LIBC_SCCS and not lint */
10
__FBSDID("$FreeBSD$");
11
12
#include "namespace.h"
13
14
#include <assert.h>
15
#include <errno.h>
16
#include <stdlib.h>
17
18
#ifndef _DIAGASSERT
19
#define _DIAGASSERT(X)
20
#endif
21
22
char *
23
l64a (long value)
24
{
25
	static char buf[8];
26
27
	(void)l64a_r(value, buf, sizeof (buf));
28
	return buf;
29
}
30
31
int
32
l64a_r (long value, char *buffer, int buflen)
33
{
34
	char *s = buffer;
35
	int digit;
36
	unsigned long v = value;
37
38
	_DIAGASSERT(buffer != NULL);
39
40
	if (value == 0UL) 
41
		goto out;
42
43
	for (; v != 0 && buflen > 1; s++, buflen--) {
44
		digit = (int)(v & 0x3f);
45
46
		if (digit < 2) 
47
			*s = digit + '.';
48
		else if (digit < 12)
49
			*s = digit + '0' - 2;
50
		else if (digit < 38)
51
			*s = digit + 'A' - 12;
52
		else
53
			*s = digit + 'a' - 38;
54
		v >>= 6;
55
	}
56
57
out:
58
	*s = '\0';
59
60
	return (v == 0UL ? 0 : -1);
61
}
(-)src/include/stdlib.h (-2 / +3 lines)
Lines 174-180 Link Here
174
 */
174
 */
175
#if __XSI_VISIBLE
175
#if __XSI_VISIBLE
176
/* XXX XSI requires pollution from <sys/wait.h> here.  We'd rather not. */
176
/* XXX XSI requires pollution from <sys/wait.h> here.  We'd rather not. */
177
/* long	 a64l(const char *); */
177
long	 a64l(const char *);
178
double	 drand48(void);
178
double	 drand48(void);
179
/* char	*ecvt(double, int, int * __restrict, int * __restrict); */
179
/* char	*ecvt(double, int, int * __restrict, int * __restrict); */
180
double	 erand48(unsigned short[3]);
180
double	 erand48(unsigned short[3]);
Lines 187-193 Link Here
187
int	 grantpt(int);
187
int	 grantpt(int);
188
char	*initstate(unsigned long /* XSI requires u_int */, char *, long);
188
char	*initstate(unsigned long /* XSI requires u_int */, char *, long);
189
long	 jrand48(unsigned short[3]);
189
long	 jrand48(unsigned short[3]);
190
/* char	*l64a(long); */
190
char	*l64a(long);
191
void	 lcong48(unsigned short[7]);
191
void	 lcong48(unsigned short[7]);
192
long	 lrand48(void);
192
long	 lrand48(void);
193
#ifndef _MKSTEMP_DECLARED
193
#ifndef _MKSTEMP_DECLARED
Lines 247-252 Link Here
247
	 getprogname(void);
247
	 getprogname(void);
248
248
249
int	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
249
int	 heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
250
int	 l64a_r (long, char *, int);
250
int	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
251
int	 mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
251
void	 qsort_r(void *, size_t, size_t, void *,
252
void	 qsort_r(void *, size_t, size_t, void *,
252
	    int (*)(void *, const void *, const void *));
253
	    int (*)(void *, const void *, const void *));

Return to bug 51209