-
-#if !HAVE_STRTOUMAX
-
-static uintmax_t
-my_strtoumax (char const *ptr, char **endptr, int base)
-{
-# define USE_IF_EQUIVALENT(function) \
- if (sizeof (uintmax_t) == sizeof function (ptr, endptr, base)) \
- return function (ptr, endptr, base);
-
- USE_IF_EQUIVALENT (strtoul)
-
-# if HAVE_STRTOULL
- USE_IF_EQUIVALENT (strtoull)
-# endif
-
-# if HAVE_STRTOUQ
- USE_IF_EQUIVALENT (strtouq)
-# endif
-
- {
- /* An implementation with uintmax_t longer than long, but with no
- known way to convert it. Do it by hand. Assume base 10. */
- uintmax_t n = 0;
- uintmax_t overflow = 0;
- for (; '0' <= *ptr && *ptr <= '9'; ptr++)
- {
- uintmax_t n10 = n * 10;
- int digit = *ptr - '0';
- overflow |= n ^ (n10 + digit) / 10;
- n = n10 + digit;
- }
- if (endptr)
- *endptr = (char *) ptr;
- if (overflow)
- {
- errno = ERANGE;
- n = (uintmax_t) -1;
- }
- return n;
- }
-}
-#endif /* HAVE_STRTOUMAX */