From 21f1794606dce19928cf455029e173321f166380 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 24 Jun 2003 05:11:53 +0000 Subject: [PATCH] 1474. [port] Provide strtoul() and memmove() for platforms without them. --- CHANGES | 3 + bin/dig/host.c | 4 +- bin/tests/genrandom.c | 5 +- bin/tests/serial_test.c | 4 +- configure | 184 +++++++++++++++++++++++++++++- configure.in | 12 +- lib/dns/rdata.c | 3 +- lib/isc/Makefile.in | 8 +- lib/isc/include/isc/platform.h.in | 12 +- lib/isc/include/isc/stdlib.h | 38 ++++++ lib/isc/include/isc/string.h | 6 +- lib/isc/parseint.c | 4 +- lib/isc/print.c | 4 +- lib/isc/strtoul.c | 127 +++++++++++++++++++++ lib/isccc/cc.c | 9 +- util/copyrights | 2 + 16 files changed, 402 insertions(+), 23 deletions(-) create mode 100644 lib/isc/include/isc/stdlib.h create mode 100644 lib/isc/strtoul.c diff --git a/CHANGES b/CHANGES index 0819e9153b..55923de734 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +1474. [port] Provide strtoul() and memmove() for platforms + without them. + 1473. [bug] free_map() and free_string() failed to handle out of memory cleanup. [RT #6813] diff --git a/bin/dig/host.c b/bin/dig/host.c index 366ca458f6..64c8e871aa 100644 --- a/bin/dig/host.c +++ b/bin/dig/host.c @@ -15,10 +15,9 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: host.c,v 1.91 2002/12/11 06:31:37 marka Exp $ */ +/* $Id: host.c,v 1.92 2003/06/24 05:10:31 marka Exp $ */ #include -#include #include #include @@ -28,6 +27,7 @@ #include #include #include +#include #include #include diff --git a/bin/tests/genrandom.c b/bin/tests/genrandom.c index 800623ccaf..794ce785fc 100644 --- a/bin/tests/genrandom.c +++ b/bin/tests/genrandom.c @@ -15,14 +15,15 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: genrandom.c,v 1.9 2002/12/04 01:19:28 marka Exp $ */ +/* $Id: genrandom.c,v 1.10 2003/06/24 05:10:31 marka Exp $ */ #include #include -#include #include +#include + int main(int argc, char **argv) { unsigned int bytes; diff --git a/bin/tests/serial_test.c b/bin/tests/serial_test.c index 8dc209fb28..63520d05b4 100644 --- a/bin/tests/serial_test.c +++ b/bin/tests/serial_test.c @@ -15,14 +15,14 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: serial_test.c,v 1.11 2001/11/27 01:55:22 gson Exp $ */ +/* $Id: serial_test.c,v 1.12 2003/06/24 05:10:31 marka Exp $ */ #include #include -#include #include +#include int main() { diff --git a/configure b/configure index 5f81358094..55af0318f6 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 1.342 . +# From configure.in Revision: 1.343 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.53. # @@ -12946,6 +12946,186 @@ fi rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +echo "$as_me:$LINENO: checking for memmove" >&5 +echo $ECHO_N "checking for memmove... $ECHO_C" >&6 +if test "${ac_cv_func_memmove+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" +/* From autoconf 2.57 */ +/* Define memmove to an innocuous variant, in case declares memmove. + For example, HP-UX 11i declares gettimeofday. */ +#define memmove innocuous_memmove + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char memmove (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef memmove + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char memmove (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_memmove) || defined (__stub___memmove) +choke me +#else +char (*f) () = memmove; +#endif +#ifdef __cplusplus +} +#endif + +#ifdef F77_DUMMY_MAIN +# ifdef __cplusplus + extern "C" +# endif + int F77_DUMMY_MAIN() { return 1; } +#endif +int +main () +{ +return f != memmove; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_func_memmove=yes +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +ac_cv_func_memmove=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_func_memmove" >&5 +echo "${ECHO_T}$ac_cv_func_memmove" >&6 +if test $ac_cv_func_memmove = yes; then + ISC_PLATFORM_NEEDMEMMOVE="#undef ISC_PLATFORM_NEEDMEMMOVE" +else + ISC_PLATFORM_NEEDMEMMOVE="#define ISC_PLATFORM_NEEDMEMMOVE 1" +fi + + + +echo "$as_me:$LINENO: checking for strtoul" >&5 +echo $ECHO_N "checking for strtoul... $ECHO_C" >&6 +if test "${ac_cv_func_strtoul+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" +/* From autoconf 2.57 */ +/* Define strtoul to an innocuous variant, in case declares strtoul. + For example, HP-UX 11i declares gettimeofday. */ +#define strtoul innocuous_strtoul + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char strtoul (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef strtoul + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char strtoul (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_strtoul) || defined (__stub___strtoul) +choke me +#else +char (*f) () = strtoul; +#endif +#ifdef __cplusplus +} +#endif + +#ifdef F77_DUMMY_MAIN +# ifdef __cplusplus + extern "C" +# endif + int F77_DUMMY_MAIN() { return 1; } +#endif +int +main () +{ +return f != strtoul; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_func_strtoul=yes +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +ac_cv_func_strtoul=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_func_strtoul" >&5 +echo "${ECHO_T}$ac_cv_func_strtoul" >&6 +if test $ac_cv_func_strtoul = yes; then + ISC_PLATFORM_NEEDSTRTOUL="#undef ISC_PLATFORM_NEEDSTRTOUL" +else + ISC_PLATFORM_NEEDSTRTOUL="#define ISC_PLATFORM_NEEDSTRTOUL 1" +fi + + + echo "$as_me:$LINENO: checking for strlcpy" >&5 echo $ECHO_N "checking for strlcpy... $ECHO_C" >&6 if test "${ac_cv_func_strlcpy+set}" = set; then @@ -15406,6 +15586,8 @@ s,@ISC_LWRES_GETIPNODEPROTO@,$ISC_LWRES_GETIPNODEPROTO,;t t s,@ISC_LWRES_GETADDRINFOPROTO@,$ISC_LWRES_GETADDRINFOPROTO,;t t s,@ISC_LWRES_GETNAMEINFOPROTO@,$ISC_LWRES_GETNAMEINFOPROTO,;t t s,@ISC_PLATFORM_NEEDSTRSEP@,$ISC_PLATFORM_NEEDSTRSEP,;t t +s,@ISC_PLATFORM_NEEDMEMMOVE@,$ISC_PLATFORM_NEEDMEMMOVE,;t t +s,@ISC_PLATFORM_NEEDSTRTOUL@,$ISC_PLATFORM_NEEDSTRTOUL,;t t s,@ISC_PLATFORM_NEEDSTRLCPY@,$ISC_PLATFORM_NEEDSTRLCPY,;t t s,@ISC_PLATFORM_NEEDSTRLCAT@,$ISC_PLATFORM_NEEDSTRLCAT,;t t s,@ISC_PLATFORM_NEEDVSNPRINTF@,$ISC_PLATFORM_NEEDVSNPRINTF,;t t diff --git a/configure.in b/configure.in index 2ebfe3b30a..dd2624b289 100644 --- a/configure.in +++ b/configure.in @@ -18,7 +18,7 @@ AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)dnl esyscmd([sed "s/^/# /" COPYRIGHT])dnl AC_DIVERT_POP()dnl -AC_REVISION($Revision: 1.342 $) +AC_REVISION($Revision: 1.343 $) AC_INIT(lib/dns/name.c) AC_PREREQ(2.13) @@ -1575,6 +1575,16 @@ AC_TRY_LINK([#include ], [char *sp; char *foo = strsep(&sp, ".");], [AC_MSG_RESULT(no); ISC_PLATFORM_NEEDSTRSEP="#define ISC_PLATFORM_NEEDSTRSEP 1"]) AC_SUBST(ISC_PLATFORM_NEEDSTRSEP) +AC_CHECK_FUNC(memmove, + [ISC_PLATFORM_NEEDMEMMOVE="#undef ISC_PLATFORM_NEEDMEMMOVE"], + [ISC_PLATFORM_NEEDMEMMOVE="#define ISC_PLATFORM_NEEDMEMMOVE 1"]) +AC_SUBST(ISC_PLATFORM_NEEDMEMMOVE) + +AC_CHECK_FUNC(strtoul, + [ISC_PLATFORM_NEEDSTRTOUL="#undef ISC_PLATFORM_NEEDSTRTOUL"], + [ISC_PLATFORM_NEEDSTRTOUL="#define ISC_PLATFORM_NEEDSTRTOUL 1"]) +AC_SUBST(ISC_PLATFORM_NEEDSTRTOUL) + AC_CHECK_FUNC(strlcpy, [ISC_PLATFORM_NEEDSTRLCPY="#undef ISC_PLATFORM_NEEDSTRLCPY"], [ISC_PLATFORM_NEEDSTRLCPY="#define ISC_PLATFORM_NEEDSTRLCPY 1"]) diff --git a/lib/dns/rdata.c b/lib/dns/rdata.c index d2c9c2cd74..9ad903a670 100644 --- a/lib/dns/rdata.c +++ b/lib/dns/rdata.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rdata.c,v 1.174 2003/04/11 07:25:25 marka Exp $ */ +/* $Id: rdata.c,v 1.175 2003/06/24 05:10:32 marka Exp $ */ #include #include @@ -27,6 +27,7 @@ #include #include #include +#include #include #include diff --git a/lib/isc/Makefile.in b/lib/isc/Makefile.in index c5121505e1..e826ba7bf1 100644 --- a/lib/isc/Makefile.in +++ b/lib/isc/Makefile.in @@ -13,7 +13,7 @@ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# $Id: Makefile.in,v 1.76 2002/10/24 03:52:32 marka Exp $ +# $Id: Makefile.in,v 1.77 2003/06/24 05:10:32 marka Exp $ srcdir = @srcdir@ VPATH = @srcdir@ @@ -57,8 +57,8 @@ OBJS = @ISC_EXTRA_OBJS@ \ mem.@O@ mutexblock.@O@ netaddr.@O@ netscope.@O@ ondestroy.@O@ \ parseint.@O@ quota.@O@ random.@O@ \ ratelimiter.@O@ region.@O@ result.@O@ rwlock.@O@ \ - serial.@O@ sha1.@O@ sockaddr.@O@ string.@O@ symtab.@O@ \ - task.@O@ taskpool.@O@ timer.@O@ version.@O@ \ + serial.@O@ sha1.@O@ sockaddr.@O@ string.@O@ strtoul.@O@ \ + symtab.@O@ task.@O@ taskpool.@O@ timer.@O@ version.@O@ \ ${UNIXOBJS} ${NLSOBJS} ${THREADOBJS} # Alphabetically @@ -70,7 +70,7 @@ SRCS = @ISC_EXTRA_SRCS@ \ md5.c mem.c mutexblock.c netaddr.c netscope.c ondestroy.c \ parseint.c quota.c random.c \ ratelimiter.c result.c rwlock.c \ - serial.c sha1.c sockaddr.c string.c symtab.c \ + serial.c sha1.c sockaddr.c string.c strtoul.c symtab.c \ task.c taskpool.c timer.c version.c LIBS = @LIBS@ diff --git a/lib/isc/include/isc/platform.h.in b/lib/isc/include/isc/platform.h.in index 836b372dc7..6c9edb46df 100644 --- a/lib/isc/include/isc/platform.h.in +++ b/lib/isc/include/isc/platform.h.in @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: platform.h.in,v 1.31 2003/04/10 04:46:27 marka Exp $ */ +/* $Id: platform.h.in,v 1.32 2003/06/24 05:10:33 marka Exp $ */ #ifndef ISC_PLATFORM_H #define ISC_PLATFORM_H 1 @@ -195,6 +195,16 @@ */ @ISC_PLATFORM_HAVEIFNAMETOINDEX@ +/* + * Define if this system needs strtoul. + */ +@ISC_PLATFORM_NEEDSTRTOUL@ + +/* + * Define if this system needs memmove. + */ +@ISC_PLATFORM_NEEDMEMMOVE@ + #ifndef ISC_PLATFORM_USEDECLSPEC #define LIBISC_EXTERNAL_DATA #define LIBDNS_EXTERNAL_DATA diff --git a/lib/isc/include/isc/stdlib.h b/lib/isc/include/isc/stdlib.h new file mode 100644 index 0000000000..afec1371be --- /dev/null +++ b/lib/isc/include/isc/stdlib.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2003 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: stdlib.h,v 1.1 2003/06/24 05:10:33 marka Exp $ */ + +#ifndef ISC_STDLIB_H +#define ISC_STDLIB_H 1 + +#include + +#include +#include + +#ifdef ISC_PLATFORM_NEEDSTRTOUL +#define strtoul isc_strtoul +#endif + +ISC_LANG_BEGINDECLS + +unsigned long isc_strtoul(const char *, char **, int); + +ISC_LANG_ENDDECLS + +#endif diff --git a/lib/isc/include/isc/string.h b/lib/isc/include/isc/string.h index 4c34629f75..dacacd90cf 100644 --- a/lib/isc/include/isc/string.h +++ b/lib/isc/include/isc/string.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: string.h,v 1.10 2003/04/10 04:46:27 marka Exp $ */ +/* $Id: string.h,v 1.11 2003/06/24 05:10:33 marka Exp $ */ #ifndef ISC_STRING_H #define ISC_STRING_H 1 @@ -51,6 +51,10 @@ isc_string_separate(char **stringp, const char *delim); #define strsep isc_string_separate #endif +#ifdef ISC_PLATFORM_NEEDMEMMOVE +#define memmove(a,b,c) bcopy(b,a,c) +#endif + size_t isc_string_strlcpy(char *dst, const char *src, size_t size); diff --git a/lib/isc/parseint.c b/lib/isc/parseint.c index 8450f0fdcb..1f6b2e46c3 100644 --- a/lib/isc/parseint.c +++ b/lib/isc/parseint.c @@ -15,17 +15,17 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: parseint.c,v 1.2 2002/02/28 20:08:05 bwelling Exp $ */ +/* $Id: parseint.c,v 1.3 2003/06/24 05:10:32 marka Exp $ */ #include #include #include #include -#include #include #include +#include isc_result_t isc_parse_uint32(isc_uint32_t *uip, const char *string, int base) { diff --git a/lib/isc/print.c b/lib/isc/print.c index d15b434625..ec953fd1ba 100644 --- a/lib/isc/print.c +++ b/lib/isc/print.c @@ -15,13 +15,12 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: print.c,v 1.23 2003/02/25 21:32:07 marka Exp $ */ +/* $Id: print.c,v 1.24 2003/06/24 05:10:32 marka Exp $ */ #include #include #include /* for sprintf */ -#include #define ISC__PRINT_SOURCE /* Used to get the isc_print_* prototypes. */ @@ -29,6 +28,7 @@ #include #include #include +#include #include /* diff --git a/lib/isc/strtoul.c b/lib/isc/strtoul.c new file mode 100644 index 0000000000..8c27f0d8ff --- /dev/null +++ b/lib/isc/strtoul.c @@ -0,0 +1,127 @@ +/* + * Portions Copyright (C) 2003 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strtoul.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +/* $Id: strtoul.c,v 1.1 2003/06/24 05:10:32 marka Exp $ */ + +#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 +isc_strtoul(const char *nptr, char **endptr, int base) { + const char *s = nptr; + unsigned long acc; + unsigned char c; + unsigned long cutoff; + int neg = 0, any, cutlim; + + /* + * See strtol for comments as to the logic used. + */ + do { + c = *s++; + } while (isspace(c)); + if (c == '-') { + neg = 1; + c = *s++; + } else 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 = (unsigned long)ULONG_MAX / (unsigned long)base; + cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; + for (acc = 0, any = 0;; c = *s++) { + if (!isascii(c)) + break; + 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 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = ULONG_MAX; + errno = ERANGE; + } else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/lib/isccc/cc.c b/lib/isccc/cc.c index 5ddc4c7459..cd322a4c5a 100644 --- a/lib/isccc/cc.c +++ b/lib/isccc/cc.c @@ -16,20 +16,21 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: cc.c,v 1.7 2003/04/11 07:25:28 marka Exp $ */ +/* $Id: cc.c,v 1.8 2003/06/24 05:10:34 marka Exp $ */ #include #include -#include #include #include -#include #include +#include +#include + +#include #include #include -#include #include #include #include diff --git a/util/copyrights b/util/copyrights index 6d8bb669c4..1692f450f0 100644 --- a/util/copyrights +++ b/util/copyrights @@ -1926,6 +1926,7 @@ ./lib/isc/include/isc/sockaddr.h C 1998,1999,2000,2001,2002 ./lib/isc/include/isc/socket.h C 1998,1999,2000,2001 ./lib/isc/include/isc/stdio.h C 2000,2001 +./lib/isc/include/isc/stdlib.h C 2003 ./lib/isc/include/isc/string.h C 2000,2001 ./lib/isc/include/isc/symtab.h C 1996,1997,1998,1999,2000,2001 ./lib/isc/include/isc/task.h C 1998,1999,2000,2001 @@ -1988,6 +1989,7 @@ ./lib/isc/sha1.c C 2000,2001 ./lib/isc/sockaddr.c C 1999,2000,2001,2002 ./lib/isc/string.c C 1999,2000,2001 +./lib/isc/strtoul.c C.PORTION 2003 ./lib/isc/symtab.c C 1996,1997,1998,1999,2000,2001 ./lib/isc/task.c C 1998,1999,2000,2001 ./lib/isc/task_p.h C 2000,2001