From 27a5bb33ac41b838dd3c4ebdc3a75a6ad666dfc7 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 7 Apr 1998 16:28:09 +0000 Subject: Update. 1998-04-07 16:18 Ulrich Drepper * libc.map: Add __asprintf to GLIBC_2.1. * elf/dlerror.c: Use __asprintf, not asprintf. * libio/stdio.h: Declare __asprintf. * stdio-common/asprintf.c: Define as __asprintf and make asprintf a weak alias. * elf/dl-minimal.c: Add definition of strtol and strtoul (und friends) to avoid inclusion from libc_pic.a. * elf/dl-runtime.c: Undo last patch. * stdlib/strtod.c: Don't use mbtowc, use btowc. * sysdeps/i386/dl-machine.h (dl_platform_init): Don't use "i386" as default, use NULL. --- elf/dl-minimal.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) (limited to 'elf/dl-minimal.c') diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c index 6592ca0..4c15d83 100644 --- a/elf/dl-minimal.c +++ b/elf/dl-minimal.c @@ -18,6 +18,7 @@ Boston, MA 02111-1307, USA. */ #include +#include #include #include #include @@ -202,3 +203,129 @@ __assert_perror_fail (int errnum, } #endif + +/* This function is only used in eval.c. */ +long int +weak_function +__strtol_internal (const char *nptr, char **endptr, int base, int group) +{ + long int result = 0; + long int sign = 1; + + while (*nptr == ' ' || *nptr == '\t') + ++nptr; + + if (*nptr == '-') + { + sign = -1; + ++nptr; + } + else if (*nptr == '+') + ++nptr; + + if (*nptr < '0' || *nptr > '9') + { + if (endptr != NULL) + *endptr = (char *) nptr; + return 0L; + } + + assert (base == 0); + if (*nptr == '0') + { + if (nptr[1] == 'x' || nptr[1] == 'X') + { + base = 16; + nptr += 2; + } + else + base = 8; + } + else + base = 10; + + while (*nptr >= '0' && *nptr <= '9') + { + long int digval = *nptr - '0'; + if (result > LONG_MAX / 10 + || (result == (sign ? LONG_MAX : LONG_MAX + 1) / 10 + && digval > (sign ? LONG_MAX : LONG_MAX + 1) % 10)) + { + errno = ERANGE; + return LONG_MAX * sign; + } + result *= 10; + result += digval; + } + + return result * sign; +} + +long int +weak_function +strtol (const char *nptr, char **endptr, int base) +{ + return __strtol_internal (nptr, endptr, base, 0); +} + +unsigned long int +weak_function +__strtoul_internal (const char *nptr, char **endptr, int base, int group) +{ + long int result = 0; + long int sign = 1; + + while (*nptr == ' ' || *nptr == '\t') + ++nptr; + + if (*nptr == '-') + { + sign = -1; + ++nptr; + } + else if (*nptr == '+') + ++nptr; + + if (*nptr < '0' || *nptr > '9') + { + if (endptr != NULL) + *endptr = (char *) nptr; + return 0UL; + } + + assert (base == 0); + if (*nptr == '0') + { + if (nptr[1] == 'x' || nptr[1] == 'X') + { + base = 16; + nptr += 2; + } + else + base = 8; + } + else + base = 10; + + while (*nptr >= '0' && *nptr <= '9') + { + long int digval = *nptr - '0'; + if (result > LONG_MAX / 10 + || (result == ULONG_MAX / 10 && digval > ULONG_MAX % 10)) + { + errno = ERANGE; + return ULONG_MAX; + } + result *= 10; + result += digval; + } + + return result * sign; +} + +unsigned long int +weak_function +strtoul (const char *nptr, char **endptr, int base) +{ + return (unsigned long int) __strtoul_internal (nptr, endptr, base, 0); +} -- cgit v1.1