diff options
author | Ulrich Drepper <drepper@redhat.com> | 1998-04-07 16:28:09 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1998-04-07 16:28:09 +0000 |
commit | 27a5bb33ac41b838dd3c4ebdc3a75a6ad666dfc7 (patch) | |
tree | d91c99e57babfeaf64a8d686fdadd935a0c50866 /elf/dl-minimal.c | |
parent | 6ca96fe202d5031bd34794b81798651a07839075 (diff) | |
download | glibc-27a5bb33ac41b838dd3c4ebdc3a75a6ad666dfc7.tar.gz glibc-27a5bb33ac41b838dd3c4ebdc3a75a6ad666dfc7.tar.xz glibc-27a5bb33ac41b838dd3c4ebdc3a75a6ad666dfc7.zip |
Update.
1998-04-07 16:18 Ulrich Drepper <drepper@cygnus.com> * 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.
Diffstat (limited to 'elf/dl-minimal.c')
-rw-r--r-- | elf/dl-minimal.c | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c index 6592ca0baf..4c15d83f8e 100644 --- a/elf/dl-minimal.c +++ b/elf/dl-minimal.c @@ -18,6 +18,7 @@ Boston, MA 02111-1307, USA. */ #include <errno.h> +#include <limits.h> #include <string.h> #include <unistd.h> #include <sys/types.h> @@ -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); +} |