Index: include/inttypes.h =================================================================== RCS file: /home/cvs/NetBSD/src/include/inttypes.h,v retrieving revision 1.2 diff -u -r1.2 inttypes.h --- include/inttypes.h 11 Mar 2003 09:21:22 -0000 1.2 +++ include/inttypes.h 25 Nov 2004 16:51:24 -0000 @@ -43,6 +43,11 @@ #include #include +typedef struct { + intmax_t quot; /* Quotient. */ + intmax_t rem; /* Remainder. */ +} imaxdiv_t; + __BEGIN_DECLS intmax_t strtoimax __P((const char * __restrict, char ** __restrict, int)); @@ -52,6 +57,8 @@ wchar_t ** __restrict, int)); uintmax_t wcstoumax __P((const wchar_t * __restrict, wchar_t ** __restrict, int)); +intmax_t imaxabs(intmax_t); +imaxdiv_t imaxdiv(intmax_t, intmax_t); __END_DECLS #endif /* !_INTTYPES_H_ */ Index: lib/libc/include/namespace.h =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/include/namespace.h,v retrieving revision 1.95 diff -u -r1.95 namespace.h --- lib/libc/include/namespace.h 5 Oct 2004 04:45:54 -0000 1.95 +++ lib/libc/include/namespace.h 25 Nov 2004 16:47:59 -0000 @@ -298,6 +298,8 @@ #define if_indextoname _if_indextoname #define if_nameindex _if_nameindex #define if_nametoindex _if_nametoindex +#define imaxabs _imaxabs +#define imaxdiv _imaxdiv #define in6addr_any _in6addr_any #define in6addr_linklocal_allnodes _in6addr_linklocal_allnodes #define in6addr_loopback _in6addr_loopback 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 25 Nov 2004 16:52:47 -0000 @@ -15,7 +15,7 @@ strsuftoll.c strtod.c \ 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 + __unsetenv13.c unsetenv.c imaxabs.c imaxdiv.c # machine-dependent stdlib sources # m-d Makefile.inc must include sources for: Index: lib/libc/stdlib/_abs_template.h =================================================================== RCS file: lib/libc/stdlib/_abs_template.h diff -N lib/libc/stdlib/_abs_template.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdlib/_abs_template.h 25 Nov 2004 17:29:32 -0000 @@ -0,0 +1,45 @@ +/* $NetBSD$ */ + +/*- + * 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: + * @(#)abs.c 8.1 (Berkeley) 6/4/93 + * NetBSD: abs.c,v 1.7 2003/08/07 16:43:37 agc Exp + */ + +/* + * function template for abs, labs, llabs, qabs and imaxabs + */ + +_INTTYPE +_FUNCNAME(j) + _INTTYPE j; +{ + return(j < 0 ? -j : j); +} Index: lib/libc/stdlib/_div_template.h =================================================================== RCS file: lib/libc/stdlib/_div_template.h diff -N lib/libc/stdlib/_div_template.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdlib/_div_template.h 25 Nov 2004 17:30:08 -0000 @@ -0,0 +1,79 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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: + * @(#)div.c 8.1 (Berkeley) 6/4/93 + * NetBSD: div.c,v 1.7 2003/08/07 16:43:39 agc Exp + */ + +/* + * function template for div, ldiv, lldiv, qabs and imaxdiv + */ + +_DIVTYPE +_FUNCNAME(num, denom) + _INTTYPE num, denom; +{ + _DIVTYPE r; + + r.quot = num / denom; + r.rem = num % denom; + /* + * The ANSI standard says that |r.quot| <= |n/d|, where + * n/d is to be computed in infinite precision. In other + * words, we should always truncate the quotient towards + * 0, never -infinity. + * + * Machine division and remainer may work either way when + * one or both of n or d is negative. If only one is + * negative and r.quot has been truncated towards -inf, + * r.rem will have the same sign as denom and the opposite + * sign of num; if both are negative and r.quot has been + * truncated towards -inf, r.rem will be positive (will + * have the opposite sign of num). These are considered + * `wrong'. + * + * If both are num and denom are positive, r will always + * be positive. + * + * This all boils down to: + * if num >= 0, but r.rem < 0, we got the wrong answer. + * In that case, to get the right answer, add 1 to r.quot and + * subtract denom from r.rem. + */ + if (num >= 0 && r.rem < 0) { + r.quot++; + r.rem -= denom; + } + return (r); +} Index: lib/libc/stdlib/abs.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/abs.c,v retrieving revision 1.7 diff -u -r1.7 abs.c --- lib/libc/stdlib/abs.c 7 Aug 2003 16:43:37 -0000 1.7 +++ lib/libc/stdlib/abs.c 25 Nov 2004 16:40:42 -0000 @@ -40,9 +40,7 @@ #include -int -abs(j) - int j; -{ - return(j < 0 ? -j : j); -} +#define _INTTYPE int +#define _FUNCNAME abs + +#include "_abs_template.h" Index: lib/libc/stdlib/div.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/div.c,v retrieving revision 1.7 diff -u -r1.7 div.c --- lib/libc/stdlib/div.c 7 Aug 2003 16:43:39 -0000 1.7 +++ lib/libc/stdlib/div.c 25 Nov 2004 16:42:05 -0000 @@ -43,40 +43,8 @@ #include /* div_t */ -div_t -div(num, denom) - int num, denom; -{ - div_t r; +#define _DIVTYPE div_t +#define _FUNCNAME div +#define _INTTYPE int - r.quot = num / denom; - r.rem = num % denom; - /* - * The ANSI standard says that |r.quot| <= |n/d|, where - * n/d is to be computed in infinite precision. In other - * words, we should always truncate the quotient towards - * 0, never -infinity. - * - * Machine division and remainer may work either way when - * one or both of n or d is negative. If only one is - * negative and r.quot has been truncated towards -inf, - * r.rem will have the same sign as denom and the opposite - * sign of num; if both are negative and r.quot has been - * truncated towards -inf, r.rem will be positive (will - * have the opposite sign of num). These are considered - * `wrong'. - * - * If both are num and denom are positive, r will always - * be positive. - * - * This all boils down to: - * if num >= 0, but r.rem < 0, we got the wrong answer. - * In that case, to get the right answer, add 1 to r.quot and - * subtract denom from r.rem. - */ - if (num >= 0 && r.rem < 0) { - r.quot++; - r.rem -= denom; - } - return (r); -} +#include "_div_template.h" Index: lib/libc/stdlib/imaxabs.c =================================================================== RCS file: lib/libc/stdlib/imaxabs.c diff -N lib/libc/stdlib/imaxabs.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdlib/imaxabs.c 25 Nov 2004 16:41:41 -0000 @@ -0,0 +1,47 @@ +/* $NetBSD$ */ + +/*- + * 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. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD$"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include + +#ifdef __weak_alias +__weak_alias(imaxabs, _imaxabs) +#endif + +#define _INTTYPE intmax_t +#define _FUNCNAME imaxabs + +#include "_abs_template.h" Index: lib/libc/stdlib/imaxdiv.c =================================================================== RCS file: lib/libc/stdlib/imaxdiv.c diff -N lib/libc/stdlib/imaxdiv.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/stdlib/imaxdiv.c 25 Nov 2004 16:45:51 -0000 @@ -0,0 +1,51 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD$"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include /* imaxdiv_t */ + +#ifdef __weak_alias +__weak_alias(imaxdiv, _imaxdiv) +#endif + +#define _DIVTYPE imaxdiv_t +#define _FUNCNAME imaxdiv +#define _INTTYPE intmax_t + +#include "_div_template.h" Index: lib/libc/stdlib/labs.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/labs.c,v retrieving revision 1.7 diff -u -r1.7 labs.c --- lib/libc/stdlib/labs.c 7 Aug 2003 16:43:41 -0000 1.7 +++ lib/libc/stdlib/labs.c 25 Nov 2004 16:41:04 -0000 @@ -40,9 +40,7 @@ #include -long -labs(j) - long j; -{ - return(j < 0 ? -j : j); -} +#define _INTTYPE long +#define _FUNCNAME labs + +#include "_abs_template.h" Index: lib/libc/stdlib/ldiv.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/ldiv.c,v retrieving revision 1.7 diff -u -r1.7 ldiv.c --- lib/libc/stdlib/ldiv.c 7 Aug 2003 16:43:41 -0000 1.7 +++ lib/libc/stdlib/ldiv.c 25 Nov 2004 16:42:25 -0000 @@ -43,19 +43,8 @@ #include /* ldiv_t */ -ldiv_t -ldiv(num, denom) - long num, denom; -{ - ldiv_t r; +#define _DIVTYPE ldiv_t +#define _FUNCNAME ldiv +#define _INTTYPE long - /* see div.c for comments */ - - r.quot = num / denom; - r.rem = num % denom; - if (num >= 0 && r.rem < 0) { - r.quot++; - r.rem -= denom; - } - return (r); -} +#include "_div_template.h" Index: lib/libc/stdlib/llabs.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/llabs.c,v retrieving revision 1.3 diff -u -r1.3 llabs.c --- lib/libc/stdlib/llabs.c 7 Aug 2003 16:43:41 -0000 1.3 +++ lib/libc/stdlib/llabs.c 25 Nov 2004 16:41:14 -0000 @@ -45,10 +45,7 @@ __weak_alias(llabs, _llabs) #endif -/* LONGLONG */ -long long int -llabs(j) - long long int j; -{ - return (j < 0 ? -j : j); -} +#define _INTTYPE /* LONGLONG */ long long int +#define _FUNCNAME llabs + +#include "_abs_template.h" Index: lib/libc/stdlib/lldiv.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/lldiv.c,v retrieving revision 1.3 diff -u -r1.3 lldiv.c --- lib/libc/stdlib/lldiv.c 7 Aug 2003 16:43:41 -0000 1.3 +++ lib/libc/stdlib/lldiv.c 25 Nov 2004 16:43:46 -0000 @@ -48,20 +48,8 @@ __weak_alias(lldiv, _lldiv) #endif -/* LONGLONG */ -lldiv_t -lldiv(num, denom) - long long int num, denom; -{ - lldiv_t r; +#define _DIVTYPE lldiv_t +#define _FUNCNAME lldiv +#define _INTTYPE /* LONGLONG */ long long int - /* see div.c for comments */ - - r.quot = num / denom; - r.rem = num % denom; - if (num >= 0 && r.rem < 0) { - r.quot++; - r.rem -= denom; - } - return (r); -} +#include "_div_template.h" Index: lib/libc/stdlib/qabs.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/qabs.c,v retrieving revision 1.6 diff -u -r1.6 qabs.c --- lib/libc/stdlib/qabs.c 7 Aug 2003 16:43:42 -0000 1.6 +++ lib/libc/stdlib/qabs.c 25 Nov 2004 17:12:19 -0000 @@ -45,9 +45,7 @@ __weak_alias(qabs,_qabs) #endif -quad_t -qabs(j) - quad_t j; -{ - return(j < 0 ? -j : j); -} +#define _INTTYPE quad_t +#define _FUNCNAME qabs + +#include "_abs_template.h" Index: lib/libc/stdlib/qdiv.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/stdlib/qdiv.c,v retrieving revision 1.6 diff -u -r1.6 qdiv.c --- lib/libc/stdlib/qdiv.c 7 Aug 2003 16:43:42 -0000 1.6 +++ lib/libc/stdlib/qdiv.c 25 Nov 2004 17:11:03 -0000 @@ -48,19 +48,8 @@ __weak_alias(qdiv,_qdiv) #endif -qdiv_t -qdiv(num, denom) - quad_t num, denom; -{ - qdiv_t r; +#define _DIVTYPE qdiv_t +#define _FUNCNAME qdiv +#define _INTTYPE quad_t - /* see div.c for comments */ - - r.quot = num / denom; - r.rem = num % denom; - if (num >= 0 && r.rem < 0) { - r.quot++; - r.rem -= denom; - } - return (r); -} +#include "_div_template.h"