1 /* xstrtoumax.c -- A more useful interface to strtoumax.
2 Copyright 1999 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /* Written by Paul Eggert. */
25 # define __strtol strtoumax
27 # define __strtol my_strtoumax
29 /* Define a temporary implementation, intended to hold the fort only
30 until glibc has an implementation of the C9x standard function
31 strtoumax. When glibc implements strtoumax, we can remove the
32 following function in favor of a replacement file strtoumax.c taken
36 # include <inttypes.h>
44 # if defined PROTOTYPES || defined __STDC__
45 # define PARAMS(Args) Args
47 # define PARAMS(Args) ()
51 static uintmax_t my_strtoumax PARAMS ((char const *, char **, int));
54 #define __strtol_t uintmax_t
55 #define __xstrtol xstrtoumax
61 my_strtoumax (char const *ptr, char **endptr, int base)
63 # define USE_IF_EQUIVALENT(function) \
64 if (sizeof (uintmax_t) == sizeof function (ptr, endptr, base)) \
65 return function (ptr, endptr, base);
67 USE_IF_EQUIVALENT (strtoul)
70 USE_IF_EQUIVALENT (strtoull)
74 USE_IF_EQUIVALENT (strtouq)
78 /* An implementation with uintmax_t longer than long, but with no
79 known way to convert it. Do it by hand. Assume base 10. */
81 uintmax_t overflow = 0;
82 for (; '0' <= *ptr && *ptr <= '9'; ptr++)
84 uintmax_t n10 = n * 10;
85 int digit = *ptr - '0';
86 overflow |= n ^ (n10 + digit) / 10;
90 *endptr = (char *) ptr;
99 #endif /* HAVE_STRTOUMAX */