Index: lib/libc/locale/Makefile.inc =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/locale/Makefile.inc,v retrieving revision 1.45 diff -u -r1.45 Makefile.inc --- lib/libc/locale/Makefile.inc 11 Mar 2003 09:21:23 -0000 1.45 +++ lib/libc/locale/Makefile.inc 29 Jan 2005 15:15:31 -0000 @@ -2,13 +2,14 @@ # $NetBSD: Makefile.inc,v 1.45 2003/03/11 09:21:23 tshiozak Exp $ # locale sources -.PATH: ${ARCHDIR}/locale ${.CURDIR}/locale +.PATH: ${ARCHDIR}/locale ${.CURDIR}/locale ${.CURDIR}/stdlib SRCS+= _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \ ctypeio.c localeconv.c nl_langinfo.c setlocale.c setlocale1.c \ setlocale32.c __mb_cur_max.c wcscoll.c wcstod.c \ wcstol.c wcstoll.c wcstoimax.c wcstoul.c wcstoull.c wcstoumax.c \ wcsxfrm.c aliasname.c +SRCS+= _wctoint.c MAN+= nl_langinfo.3 setlocale.3 MLINKS+=setlocale.3 localeconv.3 @@ -26,7 +27,7 @@ .else # citrus multibyte locale support # we have quirk for libc.a - see the last part of lib/libc/Makefile -CPPFLAGS+=-DWITH_RUNE -I${.CURDIR} +CPPFLAGS+=-DWITH_RUNE -I${.CURDIR} -I${.CURDIR}/stdlib SRCS+= ___runetype_mb.c _wctrans.c iswctype.c multibyte_c90.c \ multibyte_amd1.c rune.c runeglue.c runetable.c setrunelocale.c .endif Index: lib/libc/locale/__wctoint.h =================================================================== RCS file: lib/libc/locale/__wctoint.h diff -N lib/libc/locale/__wctoint.h --- lib/libc/locale/__wctoint.h 28 Sep 2001 11:25:37 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,79 +0,0 @@ -/* $NetBSD: __wctoint.h,v 1.1 2001/09/28 11:25:37 yamt Exp $ */ - -/*- - * Copyright (c)2001 Citrus Project, - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Citrus: xpg4dl/FreeBSD/lib/libc/locale/__wctoint.h,v 1.1 2001/09/21 13:52:32 yamt Exp $ - */ - - -__inline static int -__wctoint(wchar_t wc) -{ - int n; - - /* XXX I expect compiler to optimize this. :D */ - switch (wc) { - case L'0': n = 0; break; - case L'1': n = 1; break; - case L'2': n = 2; break; - case L'3': n = 3; break; - case L'4': n = 4; break; - case L'5': n = 5; break; - case L'6': n = 6; break; - case L'7': n = 7; break; - case L'8': n = 8; break; - case L'9': n = 9; break; - case L'A': case L'a': n = 10; break; - case L'B': case L'b': n = 11; break; - case L'C': case L'c': n = 12; break; - case L'D': case L'd': n = 13; break; - case L'E': case L'e': n = 14; break; - case L'F': case L'f': n = 15; break; - case L'G': case L'g': n = 16; break; - case L'H': case L'h': n = 17; break; - case L'I': case L'i': n = 18; break; - case L'J': case L'j': n = 19; break; - case L'K': case L'k': n = 20; break; - case L'L': case L'l': n = 21; break; - case L'M': case L'm': n = 22; break; - case L'N': case L'n': n = 23; break; - case L'O': case L'o': n = 24; break; - case L'P': case L'p': n = 25; break; - case L'Q': case L'q': n = 26; break; - case L'R': case L'r': n = 27; break; - case L'S': case L's': n = 28; break; - case L'T': case L't': n = 29; break; - case L'U': case L'u': n = 30; break; - case L'V': case L'v': n = 31; break; - case L'W': case L'w': n = 32; break; - case L'X': case L'x': n = 33; break; - case L'Y': case L'y': n = 34; break; - case L'Z': case L'z': n = 35; break; - default: n = -1; break; /* error */ - } - - return n; -} Index: lib/libc/locale/_wcstol.h =================================================================== RCS file: lib/libc/locale/_wcstol.h diff -N lib/libc/locale/_wcstol.h --- lib/libc/locale/_wcstol.h 7 Aug 2003 16:43:03 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,145 +0,0 @@ -/* $NetBSD: _wcstol.h,v 1.2 2003/08/07 16:43:03 agc Exp $ */ - -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Original version ID: - * @(#)strtol.c 8.1 (Berkeley) 6/4/93 - * NetBSD: wcstol.c,v 1.1 2001/09/27 16:30:36 yamt Exp - * Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstol.c,v 1.2 2001/09/21 16:11:41 yamt Exp - */ - -/* - * function template for wcstol, wcstoll and wcstoimax. - * - * parameters: - * _FUNCNAME : function name - * __INT : return type - * __INT_MIN : lower limit of the return type - * __INT_MAX : upper limit of the return type - */ - -__INT -_FUNCNAME(nptr, endptr, base) - const wchar_t *nptr; - wchar_t **endptr; - int base; -{ - const wchar_t *s; - __INT acc, cutoff; - wint_t wc; - int i; - int neg, any, cutlim; - - _DIAGASSERT(nptr != NULL); - /* endptr may be NULL */ - -#ifdef __GNUC__ - (void)&acc; (void)&cutoff; -#endif - - /* check base value */ - if (base && (base < 2 || base > 36)) { - errno = EINVAL; - return 0; - } - - /* - * Skip white space and pick up leading +/- sign if any. - * If base is 0, allow 0x for hex and 0 for octal, else - * assume decimal; if base is already 16, allow 0x. - */ - s = nptr; - do { - wc = (wchar_t) *s++; - } while (iswspace(wc)); - if (wc == L'-') { - neg = 1; - wc = *s++; - } else { - neg = 0; - if (wc == L'+') - wc = *s++; - } - if ((base == 0 || base == 16) && - wc == L'0' && (*s == L'x' || *s == L'X')) { - wc = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = wc == L'0' ? 8 : 10; - - /* - * See strtol for comments as to the logic used. - */ - cutoff = neg ? __INT_MIN : __INT_MAX; - cutlim = (int)(cutoff % base); - cutoff /= base; - if (neg) { - if (cutlim > 0) { - cutlim -= base; - cutoff += 1; - } - cutlim = -cutlim; - } - for (acc = 0, any = 0;; wc = (wchar_t) *s++) { - i = __wctoint(wc); - if (i == -1) - break; - if (i >= base) - break; - if (any < 0) - continue; - if (neg) { - if (acc < cutoff || (acc == cutoff && i > cutlim)) { - any = -1; - acc = __INT_MIN; - errno = ERANGE; - } else { - any = 1; - acc *= base; - acc -= i; - } - } else { - if (acc > cutoff || (acc == cutoff && i > cutlim)) { - any = -1; - acc = __INT_MAX; - errno = ERANGE; - } else { - any = 1; - acc *= base; - acc += i; - } - } - } - if (endptr != 0) - /* LINTED interface specification */ - *endptr = (wchar_t *)(any ? s - 1 : nptr); - return (acc); -} Index: lib/libc/locale/_wcstoul.h =================================================================== RCS file: lib/libc/locale/_wcstoul.h diff -N lib/libc/locale/_wcstoul.h --- lib/libc/locale/_wcstoul.h 7 Aug 2003 16:43:03 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,121 +0,0 @@ -/* $NetBSD: _wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp $ */ - -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Original version ID: - * @(#)strtoul.c 8.1 (Berkeley) 6/4/93 - * Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstoul.c,v 1.2 2001/09/21 16:11:41 yamt Exp - * NetBSD: wcstoul.c,v 1.1 2001/09/27 16:30:37 yamt Exp - */ - -/* - * function template for wcstoul, wcstoull and wcstoumax. - * - * parameters: - * _FUNCNAME : function name - * __UINT : return type - * __UINT_MAX : upper limit of the return type - */ - -__UINT -_FUNCNAME(nptr, endptr, base) - const wchar_t *nptr; - wchar_t **endptr; - int base; -{ - const wchar_t *s; - __UINT acc, cutoff; - wint_t wc; - int i; - int neg, any, cutlim; - - _DIAGASSERT(nptr != NULL); - /* endptr may be NULL */ - - if (base && (base < 2 || base > 36)) { - errno = EINVAL; - return 0; - } - - /* - * Skip white space and pick up leading +/- sign if any. - * If base is 0, allow 0x for hex and 0 for octal, else - * assume decimal; if base is already 16, allow 0x. - */ - s = nptr; - do { - wc = (wchar_t) *s++; - } while (iswspace(wc)); - if (wc == L'-') { - neg = 1; - wc = *s++; - } else { - neg = 0; - if (wc == L'+') - wc = *s++; - } - if ((base == 0 || base == 16) && - wc == L'0' && (*s == L'x' || *s == L'X')) { - wc = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = wc == L'0' ? 8 : 10; - - /* - * See strtoul for comments as to the logic used. - */ - cutoff = __UINT_MAX / (__UINT)base; - cutlim = (int)(__UINT_MAX % (__UINT)base); - for (acc = 0, any = 0;; wc = (wchar_t) *s++) { - i = __wctoint(wc); - if (i == (wint_t)-1) - break; - if (i >= base) - break; - if (any < 0) - continue; - if (acc > cutoff || (acc == cutoff && i > cutlim)) { - any = -1; - acc = __UINT_MAX; - errno = ERANGE; - } else { - any = 1; - acc *= (__UINT)base; - acc += i; - } - } - if (neg && any > 0) - acc = -acc; - if (endptr != 0) - /* LINTED interface specification */ - *endptr = (wchar_t *)(any ? s - 1 : nptr); - return (acc); -} Index: lib/libc/locale/rune_local.h =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/locale/rune_local.h,v retrieving revision 1.7 diff -u -r1.7 rune_local.h --- lib/libc/locale/rune_local.h 2 Mar 2003 22:18:15 -0000 1.7 +++ lib/libc/locale/rune_local.h 30 Jan 2005 14:42:41 -0000 @@ -45,10 +45,7 @@ /* ___runetype_mb.c */ extern _RuneType ___runetype_mb __P((wint_t)); -/* ___tolower_mb.c */ -extern wint_t ___tolower_mb __P((wint_t)); +/* _wctoint.c */ +int _wctoint __P((wint_t)); -/* ___toupper_mb.c */ -extern wint_t ___toupper_mb __P((wint_t)); - -#endif +#endif /* _RUNE_LOCALE_H_ */ Index: lib/libc/locale/wcstoimax.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/locale/wcstoimax.c,v retrieving revision 1.2 diff -u -r1.2 wcstoimax.c --- lib/libc/locale/wcstoimax.c 21 Jun 2004 21:20:43 -0000 1.2 +++ lib/libc/locale/wcstoimax.c 28 Jan 2005 20:16:21 -0000 @@ -1,7 +1,7 @@ -/* $NetBSD: wcstoimax.c,v 1.2 2004/06/21 21:20:43 itojun Exp $ */ +/* $NetBSD$ */ /*- - * Copyright (c)2003 Citrus Project, + * Copyright (c)2003, 2005 Citrus Project, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,23 +28,28 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcstoimax.c,v 1.2 2004/06/21 21:20:43 itojun Exp $"); +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ -#include -#include -#include +#if 0 +#include "namespace.h" +#endif #include #include -#include #include -#include - -#include "__wctoint.h" +#if 0 +#define _FUNCNAME _wcstoimax +#ifdef __weak_alias +__weak_alias(wcstoimax, _wcstoimax) +#endif +#else #define _FUNCNAME wcstoimax -#define __INT intmax_t -#define __INT_MIN INTMAX_MIN -#define __INT_MAX INTMAX_MAX +#endif + +#define _NUMERIC intmax_t +#define _NUMERIC_MIN INTMAX_MIN +#define _NUMERIC_MAX INTMAX_MAX -#include "_wcstol.h" +#include "_wctype_local.h" +#include "_strtol_template.h" Index: lib/libc/locale/wcstol.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/locale/wcstol.c,v retrieving revision 1.3 diff -u -r1.3 wcstol.c --- lib/libc/locale/wcstol.c 21 Jun 2004 21:20:43 -0000 1.3 +++ lib/libc/locale/wcstol.c 28 Jan 2005 20:15:19 -0000 @@ -1,7 +1,7 @@ -/* $NetBSD: wcstol.c,v 1.3 2004/06/21 21:20:43 itojun Exp $ */ +/* $NetBSD$ */ /*- - * Copyright (c)2003 Citrus Project, + * Copyright (c)2003, 2005 Citrus Project, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,22 +28,27 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcstol.c,v 1.3 2004/06/21 21:20:43 itojun Exp $"); +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ -#include -#include -#include +#if 0 +#include "namespace.h" +#endif #include -#include #include -#include - -#include "__wctoint.h" +#if 0 +#define _FUNCNAME _wcstol +#ifdef __weak_alias +__weak_alias(wcstol, _wcstol) +#endif +#else #define _FUNCNAME wcstol -#define __INT long -#define __INT_MIN LONG_MIN -#define __INT_MAX LONG_MAX +#endif + +#define _NUMERIC long int +#define _NUMERIC_MIN LONG_MIN +#define _NUMERIC_MAX LONG_MAX -#include "_wcstol.h" +#include "_wctype_local.h" +#include "_strtol_template.h" Index: lib/libc/locale/wcstoll.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/locale/wcstoll.c,v retrieving revision 1.2 diff -u -r1.2 wcstoll.c --- lib/libc/locale/wcstoll.c 21 Jun 2004 21:20:43 -0000 1.2 +++ lib/libc/locale/wcstoll.c 28 Jan 2005 20:15:52 -0000 @@ -1,7 +1,7 @@ -/* $NetBSD: wcstoll.c,v 1.2 2004/06/21 21:20:43 itojun Exp $ */ +/* $NetBSD$ */ /*- - * Copyright (c)2003 Citrus Project, + * Copyright (c)2003, 2005 Citrus Project, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,22 +28,27 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcstoll.c,v 1.2 2004/06/21 21:20:43 itojun Exp $"); +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ -#include -#include -#include +#if 0 +#include "namespace.h" +#endif #include -#include #include -#include - -#include "__wctoint.h" +#if 0 +#define _FUNCNAME _wcstoll +#ifdef __weak_alias +__weak_alias(wcstoll, _wcstoll) +#endif +#else #define _FUNCNAME wcstoll -#define __INT /* LONGLONG */ long long int -#define __INT_MIN LLONG_MIN -#define __INT_MAX LLONG_MAX +#endif + +#define _NUMERIC /* LONGLONG */ long long int +#define _NUMERIC_MIN LLONG_MIN +#define _NUMERIC_MAX LLONG_MAX -#include "_wcstol.h" +#include "_wctype_local.h" +#include "_strtol_template.h" Index: lib/libc/locale/wcstoul.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/locale/wcstoul.c,v retrieving revision 1.3 diff -u -r1.3 wcstoul.c --- lib/libc/locale/wcstoul.c 21 Jun 2004 21:20:43 -0000 1.3 +++ lib/libc/locale/wcstoul.c 30 Jan 2005 18:45:33 -0000 @@ -1,7 +1,7 @@ -/* $NetBSD: wcstoul.c,v 1.3 2004/06/21 21:20:43 itojun Exp $ */ +/* $NetBSD$ */ /*- - * Copyright (c)2003 Citrus Project, + * Copyright (c)2003, 2005 Citrus Project, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,21 +28,26 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcstoul.c,v 1.3 2004/06/21 21:20:43 itojun Exp $"); +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ -#include -#include -#include +#if 0 +#include "namespace.h" +#endif #include -#include #include -#include - -#include "__wctoint.h" +#if 0 +#define _FUNCNAME _wcstoul +#ifdef __weak_alias +__weak_alias(wcstoul, _wcstoul) +#endif +#else #define _FUNCNAME wcstoul -#define __UINT unsigned long -#define __UINT_MAX ULONG_MAX +#endif + +#define _NUMERIC unsigned long int +#define _NUMERIC_MAX ULONG_MAX -#include "_wcstoul.h" +#include "_wctype_local.h" +#include "_strtoul_template.h" Index: lib/libc/locale/wcstoull.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/locale/wcstoull.c,v retrieving revision 1.2 diff -u -r1.2 wcstoull.c --- lib/libc/locale/wcstoull.c 21 Jun 2004 21:20:43 -0000 1.2 +++ lib/libc/locale/wcstoull.c 30 Jan 2005 18:45:55 -0000 @@ -1,7 +1,7 @@ -/* $NetBSD: wcstoull.c,v 1.2 2004/06/21 21:20:43 itojun Exp $ */ +/* $NetBSD$ */ /*- - * Copyright (c)2003 Citrus Project, + * Copyright (c)2003, 2005 Citrus Project, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,21 +28,26 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcstoull.c,v 1.2 2004/06/21 21:20:43 itojun Exp $"); +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ -#include -#include -#include +#if 0 +#include "namespace.h" +#endif #include -#include #include -#include - -#include "__wctoint.h" +#if 0 +#define _FUNCNAME _wcstoull +#ifdef __weak_alias +__weak_alias(wcstoul, _wcstoull) +#endif +#else #define _FUNCNAME wcstoull -#define __UINT /* LONGLONG */ unsigned long long int -#define __UINT_MAX ULLONG_MAX +#endif + +#define _NUMERIC /* LONGLONG */ unsigned long long int +#define _NUMERIC_MAX ULLONG_MAX -#include "_wcstoul.h" +#include "_wctype_local.h" +#include "_strtoul_template.h" Index: lib/libc/locale/wcstoumax.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/locale/wcstoumax.c,v retrieving revision 1.2 diff -u -r1.2 wcstoumax.c --- lib/libc/locale/wcstoumax.c 21 Jun 2004 21:20:43 -0000 1.2 +++ lib/libc/locale/wcstoumax.c 30 Jan 2005 18:46:15 -0000 @@ -1,7 +1,7 @@ -/* $NetBSD: wcstoumax.c,v 1.2 2004/06/21 21:20:43 itojun Exp $ */ +/* $NetBSD$ */ /*- - * Copyright (c)2003 Citrus Project, + * Copyright (c)2003, 2005 Citrus Project, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,22 +28,27 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcstoumax.c,v 1.2 2004/06/21 21:20:43 itojun Exp $"); +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ -#include -#include -#include +#if 0 +#include "namespace.h" +#endif #include #include -#include #include -#include - -#include "__wctoint.h" +#if 0 +#define _FUNCNAME _wcstoumax +#ifdef __weak_alias +__weak_alias(wcstoumax, _wcstoumax) +#endif +#else #define _FUNCNAME wcstoumax -#define __UINT uintmax_t -#define __UINT_MAX UINTMAX_MAX +#endif + +#define _NUMERIC uintmax_t +#define _NUMERIC_MAX UINTMAX_MAX -#include "_wcstoul.h" +#include "_wctype_local.h" +#include "_strtoul_template.h" Index: lib/libc/stdlib/Makefile.inc =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/Makefile.inc,v retrieving revision 1.57 diff -u -r1.57 Makefile.inc --- lib/libc/stdlib/Makefile.inc 5 Aug 2004 00:17:02 -0000 1.57 +++ lib/libc/stdlib/Makefile.inc 28 Jan 2005 18:37:53 -0000 @@ -16,6 +16,7 @@ strtoimax.c strtol.c strtoll.c strtoq.c strtoul.c strtoull.c \ strtoumax.c strtouq.c system.c tdelete.c tfind.c tsearch.c twalk.c \ __unsetenv13.c unsetenv.c +SRCS+= _ctoint.c # machine-dependent stdlib sources # m-d Makefile.inc must include sources for: Index: lib/libc/stdlib/_atoi_template.h =================================================================== RCS file: lib/libc/stdlib/_atoi_template.h diff -N lib/libc/stdlib/_atoi_template.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdlib/_atoi_template.h 30 Jan 2005 19:53:40 -0000 @@ -0,0 +1,121 @@ +/* $NetBSD$ */ + +/*- + * Copyright (c)2005 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Original version ID: + * @(#)strtol.c 8.1 (Berkeley) 6/4/93 + * NetBSD: strtol.c,v 1.16 2003/08/07 16:43:44 agc Exp + */ + +#ifndef __ATOI_TEMPLATE_H_ +#define __ATOI_TEMPLATE_H_ + +#include + +_NUMERIC +_FUNCNAME(const _CHAR *nptr) +{ + const _CHAR *s; + _INT c; + _NUMERIC acc = 0; + int val, neg; + + _DIAGASSERT(nptr != NULL); + + /* + * Skip white space. + */ + s = nptr; + do { + if ((c = _INT_C(*s)) == __L('\0')) { + s = nptr; + goto done; + } + s++; + } while (_ISSPACE(c) != 0); + + /* + * Pick up leading +/- sign if any. + */ + neg = 0; + switch (c) { + case __L('-'): + neg = 1; + /* FALLTHROUGH */ + case __L('+'): + if ((c = _INT_C(*s)) == __L('\0')) { + s = nptr; + goto done; + } + s++; + } + + for (;;) { + if ((val = _CTOINT(c)) < 0 || val >= 10) + break; + acc *= 10; + if (neg) + acc -= val; + else + acc += val; + if ((c = _INT_C(*s)) == __L('\0')) + break; + s++; + } +done: + return (acc); +} + +#endif /* __ATOI_TEMPLATE_H_ */ Index: lib/libc/stdlib/_ctoint.c =================================================================== RCS file: lib/libc/stdlib/_ctoint.c diff -N lib/libc/stdlib/_ctoint.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdlib/_ctoint.c 30 Jan 2005 18:40:10 -0000 @@ -0,0 +1,69 @@ +/* $NetBSD$ */ + +/*- + * Copyright (c)2005 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD$"); +#endif /* LIBC_SCCS and not lint */ + +#define _CTOINT_INLINE 1 +#ifndef _CTOINT_INLINE + +#include "namespace.h" +#include "local.h" + +#if 0 + +#define _CTYPE_PRIVATE +#include + +int +_ctoint(int c) +{ + return (c >= 0 && c < _CTYPE_NUM_CARS ? + (_ctype_ + 1)[c] & 0xFF : -1); +} + +#else + +#define _FUNCNAME _ctoint +#define _CHAR char +#define _INT int +#define __L(c) c + +#if 1 +#include +#define _ISDIGIT isdigit +#define _ISALPHA isalpha +#define _TOUPPER toupper +#endif + +#include "_ctoint_template.h" + +#endif +#endif /* _CTOINT_INLINE */ Index: lib/libc/stdlib/_ctoint_template.h =================================================================== RCS file: lib/libc/stdlib/_ctoint_template.h diff -N lib/libc/stdlib/_ctoint_template.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdlib/_ctoint_template.h 30 Jan 2005 14:34:25 -0000 @@ -0,0 +1,102 @@ +/* $NetBSD$ */ + +/*- + * Copyright (c)2001, 2005 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Original version ID: + * Citrus: xpg4dl/FreeBSD/lib/libc/locale/__wctoint.h,v 1.1 2001/09/21 13:52:32 yamt Exp + * NetBSD: __wctoint.h,v 1.1 2001/09/28 11:25:37 yamt Exp + */ + +#ifndef __CTOINT_TEMPLATE_H_ +#define __CTOINT_TEMPLATE_H_ + +#ifdef _CTOINT_INLINE +static __inline int +_CTOINT(_INT c) +#else +int +_FUNCNAME(_INT c) +#endif +{ + int n = -1; + +#if 0 + /* XXX: FIXME + * I expect compiler to optimize this. :D + */ + switch (c) { + case __L('0'): n = 0; break; + case __L('1'): n = 1; break; + case __L('2'): n = 2; break; + case __L('3'): n = 3; break; + case __L('4'): n = 4; break; + case __L('5'): n = 5; break; + case __L('6'): n = 6; break; + case __L('7'): n = 7; break; + case __L('8'): n = 8; break; + case __L('9'): n = 9; break; + case __L('A'): case __L('a'): n = 10; break; + case __L('B'): case __L('b'): n = 11; break; + case __L('C'): case __L('c'): n = 12; break; + case __L('D'): case __L('d'): n = 13; break; + case __L('E'): case __L('e'): n = 14; break; + case __L('F'): case __L('f'): n = 15; break; + case __L('G'): case __L('g'): n = 16; break; + case __L('H'): case __L('h'): n = 17; break; + case __L('I'): case __L('i'): n = 18; break; + case __L('J'): case __L('j'): n = 19; break; + case __L('K'): case __L('k'): n = 20; break; + case __L('L'): case __L('l'): n = 21; break; + case __L('M'): case __L('m'): n = 22; break; + case __L('N'): case __L('n'): n = 23; break; + case __L('O'): case __L('o'): n = 24; break; + case __L('P'): case __L('p'): n = 25; break; + case __L('Q'): case __L('q'): n = 26; break; + case __L('R'): case __L('r'): n = 27; break; + case __L('S'): case __L('s'): n = 28; break; + case __L('T'): case __L('t'): n = 29; break; + case __L('U'): case __L('u'): n = 30; break; + case __L('V'): case __L('v'): n = 31; break; + case __L('W'): case __L('w'): n = 32; break; + case __L('X'): case __L('x'): n = 33; break; + case __L('Y'): case __L('y'): n = 34; break; + case __L('Z'): case __L('z'): n = 35; break; + } +#else + /* XXX: FIXME + * Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ + if (_ISDIGIT(c)) + n = (int)(c - __L('0')); + else if (_ISALPHA(c)) + n = (int)(_TOUPPER(c) - __L('A')) + 10; +#endif + + return (n); +} + +#endif /* __CTOINT_TEMPLATE_H_ */ Index: lib/libc/stdlib/_ctype_local.h =================================================================== RCS file: lib/libc/stdlib/_ctype_local.h diff -N lib/libc/stdlib/_ctype_local.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdlib/_ctype_local.h 30 Jan 2005 18:41:17 -0000 @@ -0,0 +1,54 @@ +/* $NetBSD$ */ + +/*- + * Copyright (c)2005 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef __CTYPE_LOCAL_H_ +#define __CTYPE_LOCAL_H_ + +#include "namespace.h" +#include + +#define _CHAR char +#define _INT int +#define _INT_C(c) ((int)(unsigned char)(c)) +#define __L(c) c +#define _ISSPACE isspace + +#define _CTOINT _ctoint +#define _CTOINT_INLINE +#ifndef _CTOINT_INLINE +#include "local.h" +#else +#if 1 +#define _ISDIGIT isdigit +#define _ISALPHA isalpha +#define _TOUPPER toupper +#endif +#include "_ctoint_template.h" +#endif + +#endif /*__CTYPE_LOCAL_H_ */ Index: lib/libc/stdlib/_strtol_template.h =================================================================== RCS file: lib/libc/stdlib/_strtol_template.h diff -N lib/libc/stdlib/_strtol_template.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdlib/_strtol_template.h 1 Feb 2005 05:41:21 -0000 @@ -0,0 +1,219 @@ +/* $NetBSD$ */ + +/*- + * Copyright (c)2005 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Original version ID: + * @(#)strtol.c 8.1 (Berkeley) 6/4/93 + * NetBSD: strtol.c,v 1.16 2003/08/07 16:43:44 agc Exp + */ + +#ifndef __STRTOL_TEMPLATE_H_ +#define __STRTOL_TEMPLATE_H_ + +#include +#include + +/* + * Convert a string to a _NUMERIC(signed). + */ +_NUMERIC +_FUNCNAME(const _CHAR * __restrict nptr, + _CHAR ** __restrict endptr, int base) +{ + const _CHAR *s, *t; + _INT c; + _NUMERIC acc = 0, cutoff; + int cutlim, val, flags = 0; +#define _NEGATIVE 0x1 +#define _OVERFLOW 0x2 + + _DIAGASSERT(nptr != NULL); + /* endptr may be NULL */ + + s = nptr; + + /* + * Check base value (required for C99). + */ + if (base != 0 && (base < 2 || base > 36)) { + errno = EINVAL; + goto done; + } + + /* + * Skip white space. + */ + do { + if ((c = _INT_C(*s)) == __L('\0')) { + s = nptr; + goto done; + } + s++; + } while (_ISSPACE(c) != 0); + + /* + * Pick up leading +/- sign if any. + */ + switch (c) { + case __L('-'): + flags |= _NEGATIVE; + /* FALLTHROUGH */ + case __L('+'): + if ((c = _INT_C(*s)) == __L('\0')) { + s = nptr; + goto done; + } + s++; + } + + /* + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + t = nptr; + switch (base) { + case 0: case 16: + if (c != __L('0')) { + if (base == 0) + base = 10; + break; + } + t = s; + if ((c = _INT_C(*s)) == __L('\0')) + goto done; + s++; + if (c != __L('x') && c != __L('X')) { + if (base == 0) + base = 8; + break; + } + if ((c = _INT_C(*s)) == __L('\0')) { + s--; + goto done; + } + s++; + if (base == 0) + base = 16; + } + + if ((val =_CTOINT(c)) < 0 || val >= base) { + s = t; + goto done; + } + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for longs is + * [-2147483648..2147483647] and the input base is 10, + * cutoff will be set to 214748364 and cutlim to either + * 7 (positive) or 8 (negative), meaning that if we have accumulated + * a value > 214748364, or equal but the next digit is > 7 (or 8), + * the number is too big, and we will return a range error. + * + * Set any if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = (flags & _NEGATIVE) ? _NUMERIC_MIN : _NUMERIC_MAX; + cutlim = (int)(cutoff % base); + cutoff /= base; + if (flags & _NEGATIVE) { + if (cutlim > 0) { + cutlim -= base; + cutoff += 1; + } + cutlim = -cutlim; + } + + for (;;) { + if (!(flags & _OVERFLOW)) { + if (flags & _NEGATIVE) { + if (acc < cutoff || + (acc == cutoff && val > cutlim)) { + flags |= _OVERFLOW; + acc = _NUMERIC_MIN; + errno = ERANGE; + } else { + acc *= base; + acc -= val; + } + } else { + if (acc > cutoff || + (acc == cutoff && val > cutlim)) { + flags |= _OVERFLOW; + acc = _NUMERIC_MAX; + errno = ERANGE; + } else { + acc *= base; + acc += val; + } + } + } + if ((c = _INT_C(*s)) == __L('\0') || + ((val =_CTOINT(c)) < 0 || val >= base)) + break; + s++; + } +done: + if (endptr != NULL) + *endptr = __UNCONST(s); + return (acc); +} + +#endif /* __STRTOL_TEMPLATE_H_ */ Index: lib/libc/stdlib/_strtoul_template.h =================================================================== RCS file: lib/libc/stdlib/_strtoul_template.h diff -N lib/libc/stdlib/_strtoul_template.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdlib/_strtoul_template.h 1 Feb 2005 05:41:11 -0000 @@ -0,0 +1,175 @@ +/* $NetBSD$ */ + +/*- + * Copyright (c)2005 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Original version ID: + * @(#)strtoul.c 8.1 (Berkeley) 6/4/93 + * NetBSD: strtoul.c,v 1.16 2003/08/07 16:43:45 agc Exp + */ + +#ifndef __STRTOUL_TEMPLATE_H_ +#define __SETROUL_TEMPLATE_H_ + +#include +#include + +/* + * Convert a string to a _NUMERIC(unsigned). + */ +_NUMERIC +_FUNCNAME(const _CHAR * __restrict nptr, + _CHAR ** __restrict endptr, int base) +{ + const _CHAR *s, *t; + _INT c; + _NUMERIC acc = 0, cutoff; + int cutlim, val, flags = 0; +#define _NEGATIVE 0x1 +#define _OVERFLOW 0x2 + + _DIAGASSERT(nptr != NULL); + /* endptr may be NULL */ + + s = nptr; + + /* + * See strtol for comments as to the logic used. + */ + + if (base != 0 && (base < 2 || base > 36)) { + errno = EINVAL; + goto done; + } + + do { + if ((c = _INT_C(*s)) == __L('\0')) { + s = nptr; + goto done; + } + s++; + } while (_ISSPACE(c) != 0); + + switch (c) { + case __L('-'): + flags |= _NEGATIVE; + /* FALLTHROUGH */ + case __L('+'): + if ((c = _INT_C(*s)) == __L('\0')) { + s = nptr; + goto done; + } + s++; + } + + t = nptr; + switch (base) { + case 0: case 16: + if (c != __L('0')) { + if (base == 0) + base = 10; + break; + } + t = s; + if ((c = _INT_C(*s)) == __L('\0')) + goto done; + s++; + if (c != __L('x') && c != __L('X')) { + if (base == 0) + base = 8; + break; + } + if ((c = _INT_C(*s)) == __L('\0')) { + s--; + goto done; + } + s++; + if (base == 0) + base = 16; + } + + if ((val =_CTOINT(c)) < 0 || val >= base) { + s = t; + goto done; + } + + cutoff = _NUMERIC_MAX / base; + cutlim = (int)(_NUMERIC_MAX % base); + + for (;;) { + if (!(flags & _OVERFLOW)) { + if (acc > cutoff || + (acc == cutoff && val > cutlim)) { + flags |= _OVERFLOW; + acc = _NUMERIC_MAX; + errno = ERANGE; + } else { + acc *= base; + acc += val; + } + } + if ((c = _INT_C(*s)) == __L('\0') || + ((val =_CTOINT(c)) < 0 || val >= base)) + break; + s++; + } + if (!(flags & _OVERFLOW) && (flags & _NEGATIVE)) + acc = -acc; +done: + if (endptr != NULL) + *endptr = __UNCONST(s); + return (acc); +} + +#endif /* __STRTOUL_TEMPLATE_H_ */ Index: lib/libc/stdlib/atoi.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/atoi.c,v retrieving revision 1.11 diff -u -r1.11 atoi.c --- lib/libc/stdlib/atoi.c 7 Aug 2003 16:43:38 -0000 1.11 +++ lib/libc/stdlib/atoi.c 30 Jan 2005 18:37:56 -0000 @@ -1,8 +1,8 @@ -/* $NetBSD: atoi.c,v 1.11 2003/08/07 16:43:38 agc Exp $ */ +/* $NetBSD$ */ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. +/*- + * Copyright (c)2005 Citrus Project, + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,14 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -31,21 +28,13 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)atoi.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: atoi.c,v 1.11 2003/08/07 16:43:38 agc Exp $"); -#endif +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ -#include #include -int -atoi(str) - const char *str; -{ - _DIAGASSERT(str != NULL); +#define _NUMERIC int +#define _FUNCNAME atoi - return((int)strtol(str, (char **)NULL, 10)); -} +#include "_ctype_local.h" +#include "_atoi_template.h" Index: lib/libc/stdlib/atol.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/atol.c,v retrieving revision 1.10 diff -u -r1.10 atol.c --- lib/libc/stdlib/atol.c 7 Aug 2003 16:43:38 -0000 1.10 +++ lib/libc/stdlib/atol.c 30 Jan 2005 18:37:04 -0000 @@ -1,8 +1,8 @@ -/* $NetBSD: atol.c,v 1.10 2003/08/07 16:43:38 agc Exp $ */ +/* $NetBSD$ */ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. +/*- + * Copyright (c)2005 Citrus Project, + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,14 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -31,21 +28,13 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)atol.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: atol.c,v 1.10 2003/08/07 16:43:38 agc Exp $"); -#endif +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ -#include #include -long -atol(str) - const char *str; -{ - _DIAGASSERT(str != NULL); +#define _NUMERIC long int +#define _FUNCNAME atol - return(strtol(str, (char **)NULL, 10)); -} +#include "_ctype_local.h" +#include "_atoi_template.h" Index: lib/libc/stdlib/atoll.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/atoll.c,v retrieving revision 1.5 diff -u -r1.5 atoll.c --- lib/libc/stdlib/atoll.c 27 Oct 2003 00:12:42 -0000 1.5 +++ lib/libc/stdlib/atoll.c 30 Jan 2005 18:37:34 -0000 @@ -1,8 +1,8 @@ -/* $NetBSD: atoll.c,v 1.5 2003/10/27 00:12:42 lukem Exp $ */ +/* $NetBSD$ */ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. +/*- + * Copyright (c)2005 Citrus Project, + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,14 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -29,37 +26,19 @@ * SUCH DAMAGE. */ -#if HAVE_NBTOOL_CONFIG_H -#include "nbtool_config.h" -#endif - #include #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "from: @(#)atol.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: atoll.c,v 1.5 2003/10/27 00:12:42 lukem Exp $"); -#endif +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ -#ifdef _LIBC #include "namespace.h" -#endif - #include -#ifdef _LIBC +#define _NUMERIC /*LONGLONG*/ long long int +#define _FUNCNAME atoll #ifdef __weak_alias __weak_alias(atoll, _atoll) #endif -#endif -#if !HAVE_ATOLL -/* LONGLONG */ -long long int -atoll(str) - const char *str; -{ - return (strtoll(str, (char **)NULL, 10)); -} -#endif +#include "_ctype_local.h" +#include "_atoi_template.h" Index: lib/libc/stdlib/local.h =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/local.h,v retrieving revision 1.1 diff -u -r1.1 local.h --- lib/libc/stdlib/local.h 13 Jul 1997 20:16:46 -0000 1.1 +++ lib/libc/stdlib/local.h 28 Jan 2005 20:01:32 -0000 @@ -30,3 +30,4 @@ */ char *__findenv __P((const char *, int *)); +int _ctoint __P((int)); Index: lib/libc/stdlib/strtoimax.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/strtoimax.c,v retrieving revision 1.3 diff -u -r1.3 strtoimax.c --- lib/libc/stdlib/strtoimax.c 7 Aug 2003 16:43:44 -0000 1.3 +++ lib/libc/stdlib/strtoimax.c 30 Jan 2005 18:35:04 -0000 @@ -1,8 +1,8 @@ -/* $NetBSD: strtoimax.c,v 1.3 2003/08/07 16:43:44 agc Exp $ */ +/* $NetBSD$ */ /*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c)2005 Citrus Project, + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,14 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -31,139 +28,22 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "from: @(#)strtoq.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: strtoimax.c,v 1.3 2003/08/07 16:43:44 agc Exp $"); -#endif +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" - -#include -#include -#include #include -#include +#include +#include +#define _FUNCNAME _strtoimax #ifdef __weak_alias __weak_alias(strtoimax, _strtoimax) #endif -/* - * Convert a string to an intmax_t. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -intmax_t -_strtoimax(nptr, endptr, base) - const char *nptr; - char **endptr; - int base; -{ - const char *s; - intmax_t acc, cutoff; - int c; - int neg, any, cutlim; - - _DIAGASSERT(nptr != NULL); - /* endptr may be NULL */ - -#ifdef __GNUC__ - /* This outrageous construct just to shut up a GCC warning. */ - (void) &acc; (void) &cutoff; -#endif +#define _NUMERIC intmax_t +#define _NUMERIC_MIN INTMAX_MIN +#define _NUMERIC_MAX INTMAX_MAX - /* - * Skip white space and pick up leading +/- sign if any. - * If base is 0, allow 0x for hex and 0 for octal, else - * assume decimal; if base is already 16, allow 0x. - */ - s = nptr; - do { - c = (unsigned char) *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - - /* - * Compute the cutoff value between legal numbers and illegal - * numbers. That is the largest legal value, divided by the - * base. An input number that is greater than this value, if - * followed by a legal input character, is too big. One that - * is equal to this value may be valid or not; the limit - * between valid and invalid numbers is then based on the last - * digit. For instance, if the range for intmax_t is - * [-9223372036854775808..9223372036854775807] and the input base - * is 10, cutoff will be set to 922337203685477580 and cutlim to - * either 7 (neg==0) or 8 (neg==1), meaning that if we have - * accumulated a value > 922337203685477580, or equal but the - * next digit is > 7 (or 8), the number is too big, and we will - * return a range error. - * - * Set any if any `digits' consumed; make it negative to indicate - * overflow. - */ - cutoff = neg ? INTMAX_MIN : INTMAX_MAX; - cutlim = (int)(cutoff % base); - cutoff /= base; - if (neg) { - if (cutlim > 0) { - cutlim -= base; - cutoff += 1; - } - cutlim = -cutlim; - } - for (acc = 0, any = 0;; c = (unsigned char) *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0) - continue; - if (neg) { - if (acc < cutoff || (acc == cutoff && c > cutlim)) { - any = -1; - acc = INTMAX_MIN; - errno = ERANGE; - } else { - any = 1; - acc *= base; - acc -= c; - } - } else { - if (acc > cutoff || (acc == cutoff && c > cutlim)) { - any = -1; - acc = INTMAX_MAX; - errno = ERANGE; - } else { - any = 1; - acc *= base; - acc += c; - } - } - } - if (endptr != 0) - /* LINTED interface specification */ - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} +#include "_ctype_local.h" +#include "_strtol_template.h" Index: lib/libc/stdlib/strtol.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/strtol.c,v retrieving revision 1.16 diff -u -r1.16 strtol.c --- lib/libc/stdlib/strtol.c 7 Aug 2003 16:43:44 -0000 1.16 +++ lib/libc/stdlib/strtol.c 30 Jan 2005 18:33:49 -0000 @@ -1,8 +1,8 @@ -/* $NetBSD: strtol.c,v 1.16 2003/08/07 16:43:44 agc Exp $ */ +/* $NetBSD$ */ /*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c)2005 Citrus Project, + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,14 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -31,128 +28,17 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: strtol.c,v 1.16 2003/08/07 16:43:44 agc Exp $"); -#endif +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ -#include -#include -#include #include #include +#define _FUNCNAME strtol -/* - * Convert a string to a long integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -long -strtol(nptr, endptr, base) - const char *nptr; - char **endptr; - int base; -{ - const char *s; - long acc, cutoff; - int c; - int neg, any, cutlim; - - _DIAGASSERT(nptr != NULL); - /* endptr may be NULL */ - - /* - * Skip white space and pick up leading +/- sign if any. - * If base is 0, allow 0x for hex and 0 for octal, else - * assume decimal; if base is already 16, allow 0x. - */ - s = nptr; - do { - c = (unsigned char) *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - - /* - * Compute the cutoff value between legal numbers and illegal - * numbers. That is the largest legal value, divided by the - * base. An input number that is greater than this value, if - * followed by a legal input character, is too big. One that - * is equal to this value may be valid or not; the limit - * between valid and invalid numbers is then based on the last - * digit. For instance, if the range for longs is - * [-2147483648..2147483647] and the input base is 10, - * cutoff will be set to 214748364 and cutlim to either - * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated - * a value > 214748364, or equal but the next digit is > 7 (or 8), - * the number is too big, and we will return a range error. - * - * Set any if any `digits' consumed; make it negative to indicate - * overflow. - */ - cutoff = neg ? LONG_MIN : LONG_MAX; - cutlim = (int)(cutoff % base); - cutoff /= base; - if (neg) { - if (cutlim > 0) { - cutlim -= base; - cutoff += 1; - } - cutlim = -cutlim; - } - for (acc = 0, any = 0;; c = (unsigned char) *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0) - continue; - if (neg) { - if (acc < cutoff || (acc == cutoff && c > cutlim)) { - any = -1; - acc = LONG_MIN; - errno = ERANGE; - } else { - any = 1; - acc *= base; - acc -= c; - } - } else { - if (acc > cutoff || (acc == cutoff && c > cutlim)) { - any = -1; - acc = LONG_MAX; - errno = ERANGE; - } else { - any = 1; - acc *= base; - acc += c; - } - } - } - if (endptr != 0) - /* LINTED interface specification */ - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} +#define _NUMERIC long int +#define _NUMERIC_MIN LONG_MIN +#define _NUMERIC_MAX LONG_MAX + +#include "_ctype_local.h" +#include "_strtol_template.h" Index: lib/libc/stdlib/strtoll.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/strtoll.c,v retrieving revision 1.6 diff -u -r1.6 strtoll.c --- lib/libc/stdlib/strtoll.c 27 Oct 2003 00:12:42 -0000 1.6 +++ lib/libc/stdlib/strtoll.c 30 Jan 2005 18:34:14 -0000 @@ -1,8 +1,8 @@ -/* $NetBSD: strtoll.c,v 1.6 2003/10/27 00:12:42 lukem Exp $ */ +/* $NetBSD$ */ /*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c)2005 Citrus Project, + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,14 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -35,151 +32,29 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "from: @(#)strtoq.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: strtoll.c,v 1.6 2003/10/27 00:12:42 lukem Exp $"); -#endif +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ #ifdef _LIBC #include "namespace.h" #endif - -#include -#include -#include #include #include -#ifdef _LIBC +#ifndef _LIBC +#define _FUNCNAME strtoll +#else +#define _FUNCNAME _strtoll #ifdef __weak_alias __weak_alias(strtoll, _strtoll) #endif #endif -#if !HAVE_STRTOLL -/* - * Convert a string to a long long integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -/* LONGLONG */ -long long int -#ifdef _LIBC -_strtoll(nptr, endptr, base) -#else -strtoll(nptr, endptr, base) -#endif - const char *nptr; - char **endptr; - int base; -{ - const char *s; - /* LONGLONG */ - long long int acc, cutoff; - int c; - int neg, any, cutlim; - - _DIAGASSERT(nptr != NULL); - /* endptr may be NULL */ - -#ifdef __GNUC__ - /* This outrageous construct just to shut up a GCC warning. */ - (void) &acc; (void) &cutoff; -#endif +#define _NUMERIC /*LONGLONG*/long long int +#define _NUMERIC_MIN LLONG_MIN +#define _NUMERIC_MAX LLONG_MAX - /* - * Skip white space and pick up leading +/- sign if any. - * If base is 0, allow 0x for hex and 0 for octal, else - * assume decimal; if base is already 16, allow 0x. - */ - s = nptr; - do { - c = (unsigned char) *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - - /* - * Compute the cutoff value between legal numbers and illegal - * numbers. That is the largest legal value, divided by the - * base. An input number that is greater than this value, if - * followed by a legal input character, is too big. One that - * is equal to this value may be valid or not; the limit - * between valid and invalid numbers is then based on the last - * digit. For instance, if the range for long longs is - * [-9223372036854775808..9223372036854775807] and the input base - * is 10, cutoff will be set to 922337203685477580 and cutlim to - * either 7 (neg==0) or 8 (neg==1), meaning that if we have - * accumulated a value > 922337203685477580, or equal but the - * next digit is > 7 (or 8), the number is too big, and we will - * return a range error. - * - * Set any if any `digits' consumed; make it negative to indicate - * overflow. - */ - cutoff = neg ? LLONG_MIN : LLONG_MAX; - cutlim = (int)(cutoff % base); - cutoff /= base; - if (neg) { - if (cutlim > 0) { - cutlim -= base; - cutoff += 1; - } - cutlim = -cutlim; - } - for (acc = 0, any = 0;; c = (unsigned char) *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0) - continue; - if (neg) { - if (acc < cutoff || (acc == cutoff && c > cutlim)) { - any = -1; - acc = LLONG_MIN; - errno = ERANGE; - } else { - any = 1; - acc *= base; - acc -= c; - } - } else { - if (acc > cutoff || (acc == cutoff && c > cutlim)) { - any = -1; - acc = LLONG_MAX; - errno = ERANGE; - } else { - any = 1; - acc *= base; - acc += c; - } - } - } - if (endptr != 0) - /* LINTED interface specification */ - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} +#include "_ctype_local.h" +#if !HAVE_STRTOLL +#include "_strtol_template.h" #endif Index: lib/libc/stdlib/strtoq.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/strtoq.c,v retrieving revision 1.16 diff -u -r1.16 strtoq.c --- lib/libc/stdlib/strtoq.c 7 Aug 2003 16:43:44 -0000 1.16 +++ lib/libc/stdlib/strtoq.c 30 Jan 2005 18:34:44 -0000 @@ -1,8 +1,8 @@ -/* $NetBSD: strtoq.c,v 1.16 2003/08/07 16:43:44 agc Exp $ */ +/* $NetBSD$ */ /*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c)2005 Citrus Project, + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,14 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -31,135 +28,27 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)strtoq.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: strtoq.c,v 1.16 2003/08/07 16:43:44 agc Exp $"); -#endif +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ -#include - -#include -#include -#include +#if 0 +#include "namespace.h" +#endif #include #include -/* - * Convert a string to a quad integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -quad_t -strtoq(nptr, endptr, base) - const char *nptr; - char **endptr; - int base; -{ - const char *s; - quad_t acc, cutoff; - int c; - int neg, any, cutlim; - - _DIAGASSERT(nptr != NULL); - /* endptr may be NULL */ - -#ifdef __GNUC__ - /* This outrageous construct just to shut up a GCC warning. */ - (void) &acc; (void) &cutoff; +#if 0 +#define _FUNCNAME _strtoq +#ifdef __weak_alias +__weak_alias(strtoq, _strtoq) #endif +#else +#define _FUNCNAME strtoq +#endif + +#define _NUMERIC quad_t +#define _NUMERIC_MIN QUAD_MIN +#define _NUMERIC_MAX QUAD_MAX - /* - * Skip white space and pick up leading +/- sign if any. - * If base is 0, allow 0x for hex and 0 for octal, else - * assume decimal; if base is already 16, allow 0x. - */ - s = nptr; - do { - c = (unsigned char) *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - - /* - * Compute the cutoff value between legal numbers and illegal - * numbers. That is the largest legal value, divided by the - * base. An input number that is greater than this value, if - * followed by a legal input character, is too big. One that - * is equal to this value may be valid or not; the limit - * between valid and invalid numbers is then based on the last - * digit. For instance, if the range for quads is - * [-9223372036854775808..9223372036854775807] and the input base - * is 10, cutoff will be set to 922337203685477580 and cutlim to - * either 7 (neg==0) or 8 (neg==1), meaning that if we have - * accumulated a value > 922337203685477580, or equal but the - * next digit is > 7 (or 8), the number is too big, and we will - * return a range error. - * - * Set any if any `digits' consumed; make it negative to indicate - * overflow. - */ - cutoff = neg ? QUAD_MIN : QUAD_MAX; - cutlim = (int)(cutoff % base); - cutoff /= base; - if (neg) { - if (cutlim > 0) { - cutlim -= base; - cutoff += 1; - } - cutlim = -cutlim; - } - for (acc = 0, any = 0;; c = (unsigned char) *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0) - continue; - if (neg) { - if (acc < cutoff || (acc == cutoff && c > cutlim)) { - any = -1; - acc = QUAD_MIN; - errno = ERANGE; - } else { - any = 1; - acc *= base; - acc -= c; - } - } else { - if (acc > cutoff || (acc == cutoff && c > cutlim)) { - any = -1; - acc = QUAD_MAX; - errno = ERANGE; - } else { - any = 1; - acc *= base; - acc += c; - } - } - } - if (endptr != 0) - /* LINTED interface specification */ - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} +#include "_ctype_local.h" +#include "_strtol_template.h" Index: lib/libc/stdlib/strtoul.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/strtoul.c,v retrieving revision 1.16 diff -u -r1.16 strtoul.c --- lib/libc/stdlib/strtoul.c 7 Aug 2003 16:43:45 -0000 1.16 +++ lib/libc/stdlib/strtoul.c 30 Jan 2005 18:35:36 -0000 @@ -1,8 +1,8 @@ -/* $NetBSD: strtoul.c,v 1.16 2003/08/07 16:43:45 agc Exp $ */ +/* $NetBSD$ */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. +/*- + * Copyright (c)2005 Citrus Project, + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,14 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -31,90 +28,16 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)strtoul.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: strtoul.c,v 1.16 2003/08/07 16:43:45 agc Exp $"); -#endif +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ -#include -#include -#include #include #include -/* - * Convert a string to an unsigned long integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -unsigned long -strtoul(nptr, endptr, base) - const char *nptr; - char **endptr; - int base; -{ - const char *s; - unsigned long acc, cutoff; - int c; - int neg, any, cutlim; - - _DIAGASSERT(nptr != NULL); - /* endptr may be NULL */ - - /* - * See strtol for comments as to the logic used. - */ - s = nptr; - do { - c = (unsigned char) *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - - cutoff = ULONG_MAX / (unsigned long)base; - cutlim = (int)(ULONG_MAX % (unsigned long)base); - for (acc = 0, any = 0;; c = (unsigned char) *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0) - continue; - if (acc > cutoff || (acc == cutoff && c > cutlim)) { - any = -1; - acc = ULONG_MAX; - errno = ERANGE; - } else { - any = 1; - acc *= (unsigned long)base; - acc += c; - } - } - if (neg && any > 0) - acc = -acc; - if (endptr != 0) - /* LINTED interface specification */ - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} +#define _FUNCNAME strtoul + +#define _NUMERIC unsigned long int +#define _NUMERIC_MAX ULONG_MAX + +#include "_ctype_local.h" +#include "_strtoul_template.h" Index: lib/libc/stdlib/strtoull.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/strtoull.c,v retrieving revision 1.5 diff -u -r1.5 strtoull.c --- lib/libc/stdlib/strtoull.c 7 Aug 2003 16:43:45 -0000 1.5 +++ lib/libc/stdlib/strtoull.c 30 Jan 2005 18:35:57 -0000 @@ -1,8 +1,8 @@ -/* $NetBSD: strtoull.c,v 1.5 2003/08/07 16:43:45 agc Exp $ */ +/* $NetBSD$ */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. +/*- + * Copyright (c)2005 Citrus Project, + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,14 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -31,100 +28,20 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "from: @(#)strtoul.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: strtoull.c,v 1.5 2003/08/07 16:43:45 agc Exp $"); -#endif +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" -#include -#include -#include #include #include +#define _FUNCNAME _strtoull #ifdef __weak_alias __weak_alias(strtoull, _strtoull) #endif -/* - * Convert a string to an unsigned long long integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -/* LONGLONG */ -unsigned long long int -strtoull(nptr, endptr, base) - const char *nptr; - char **endptr; - int base; -{ - const char *s; - /* LONGLONG */ - unsigned long long int acc, cutoff; - int c; - int neg, any, cutlim; - - _DIAGASSERT(nptr != NULL); - /* endptr may be NULL */ - - /* - * See strtol for comments as to the logic used. - */ - s = nptr; - do { - c = (unsigned char) *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - - /* LONGLONG */ - cutoff = ULLONG_MAX / (unsigned long long int)base; - /* LONGLONG */ - cutlim = (int)(ULLONG_MAX % (unsigned long long int)base); - for (acc = 0, any = 0;; c = (unsigned char) *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0) - continue; - if (acc > cutoff || (acc == cutoff && c > cutlim)) { - any = -1; - acc = ULLONG_MAX; - errno = ERANGE; - } else { - any = 1; - /* LONGLONG */ - acc *= (unsigned long long int)base; - acc += c; - } - } - if (neg && any > 0) - acc = -acc; - if (endptr != 0) - /* LINTED interface specification */ - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} +#define _NUMERIC /* LONGLONG */ unsigned long long int +#define _NUMERIC_MAX ULLONG_MAX + +#include "_ctype_local.h" +#include "_strtoul_template.h" Index: lib/libc/stdlib/strtoumax.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/strtoumax.c,v retrieving revision 1.5 diff -u -r1.5 strtoumax.c --- lib/libc/stdlib/strtoumax.c 7 Aug 2003 16:43:45 -0000 1.5 +++ lib/libc/stdlib/strtoumax.c 30 Jan 2005 18:36:38 -0000 @@ -1,8 +1,8 @@ -/* $NetBSD: strtoumax.c,v 1.5 2003/08/07 16:43:45 agc Exp $ */ +/* $NetBSD$ */ -/* - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. +/*- + * Copyright (c)2005 Citrus Project, + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,14 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -31,96 +28,21 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "from: @(#)strtoul.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: strtoumax.c,v 1.5 2003/08/07 16:43:45 agc Exp $"); -#endif +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" - -#include -#include -#include #include -#include +#include +#include +#define _FUNCNAME _strtoumax #ifdef __weak_alias __weak_alias(strtoumax, _strtoumax) #endif -/* - * Convert a string to an uintmax_t. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -uintmax_t -_strtoumax(nptr, endptr, base) - const char *nptr; - char **endptr; - int base; -{ - const char *s; - uintmax_t acc, cutoff; - int c; - int neg, any, cutlim; - - _DIAGASSERT(nptr != NULL); - /* endptr may be NULL */ - - /* - * See strtol for comments as to the logic used. - */ - s = nptr; - do { - c = (unsigned char) *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - - cutoff = UINTMAX_MAX / (uintmax_t)base; - cutlim = (int)(UINTMAX_MAX % (uintmax_t)base); - for (acc = 0, any = 0;; c = (unsigned char) *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0) - continue; - if (acc > cutoff || (acc == cutoff && c > cutlim)) { - any = -1; - acc = UINTMAX_MAX; - errno = ERANGE; - } else { - any = 1; - acc *= (uintmax_t)base; - acc += c; - } - } - if (neg && any > 0) - acc = -acc; - if (endptr != 0) - /* LINTED interface specification */ - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} +#define _NUMERIC uintmax_t +#define _NUMERIC_MAX UINTMAX_MAX + +#include "_ctype_local.h" +#include "_strtoul_template.h" Index: lib/libc/stdlib/strtouq.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/strtouq.c,v retrieving revision 1.17 diff -u -r1.17 strtouq.c --- lib/libc/stdlib/strtouq.c 7 Aug 2003 16:43:45 -0000 1.17 +++ lib/libc/stdlib/strtouq.c 30 Jan 2005 18:36:18 -0000 @@ -1,8 +1,8 @@ -/* $NetBSD: strtouq.c,v 1.17 2003/08/07 16:43:45 agc Exp $ */ +/* $NetBSD$ */ /*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c)2005 Citrus Project, + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,14 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -31,92 +28,26 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)strtouq.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: strtouq.c,v 1.17 2003/08/07 16:43:45 agc Exp $"); -#endif +__RCSID("$NetBSD$"); #endif /* LIBC_SCCS and not lint */ -#include - -#include -#include -#include +#if 0 +#include "namespace.h" +#endif #include #include -/* - * Convert a string to an unsigned quad integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -u_quad_t -strtouq(nptr, endptr, base) - const char *nptr; - char **endptr; - int base; -{ - const char *s; - u_quad_t acc, cutoff; - int c; - int neg, any, cutlim; - - _DIAGASSERT(nptr != NULL); - /* endptr may be NULL */ - - /* - * See strtoq for comments as to the logic used. - */ - s = nptr; - do { - c = (unsigned char) *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - - cutoff = UQUAD_MAX / (u_quad_t)base; - cutlim = (int)(UQUAD_MAX % (u_quad_t)base); - for (acc = 0, any = 0;; c = (unsigned char) *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0) - continue; - if (acc > cutoff || (acc == cutoff && c > cutlim)) { - any = -1; - acc = UQUAD_MAX; - errno = ERANGE; - } else { - any = 1; - acc *= (u_quad_t)base; - acc += c; - } - } - if (neg && any > 0) - acc = -acc; - if (endptr != 0) - /* LINTED interface specification */ - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} +#if 0 +#define _FUNCNAME _strtouq +#ifdef __weak_alias +__weak_alias(strtouq, _strtouq) +#endif +#else +#define _FUNCNAME strtouq +#endif + +#define _NUMERIC u_quad_t +#define _NUMERIC_MAX UQUAD_MAX + +#include "_ctype_local.h" +#include "_strtoul_template.h"