1 /* Copyright (C) 1989-2018 Free Software Foundation, Inc.
2 Written by James Clark (jjc@jclark.com)
4 This file is part of groff.
6 groff is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 groff is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
32 #define LONG_MAX 2147483647
36 #define LONG_MIN (-LONG_MAX-1)
40 #define ISASCII(c) isascii(c)
42 #define ISASCII(c) (1)
45 long strtol(str, ptr, base)
53 static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
55 while (ISASCII((unsigned char)*str) && isspace((unsigned char)*str))
64 if (str[1] == 'x' || str[1] == 'X') {
74 if (base < 2 || base > 36)
76 else if (base == 16 && *str == '0' && (str[1] == 'x' || str[1] == 'X'))
79 p = strchr(digits, (ISASCII((unsigned char)*str)
80 && isupper((unsigned char)*str)
81 ? tolower((unsigned char)*str)
83 if (p == 0 || (val = (p - digits)) >= base) {
84 if (base == 16 && str > start && (str[-1] == 'x' || str[-1] == 'X')) {
98 while (*++str != '\0') {
101 p = strchr(digits, (ISASCII((unsigned char)*str)
102 && isupper((unsigned char)*str)
103 ? tolower((unsigned char)*str) : *str));
110 if (-(unsigned long)val > (-(unsigned long)LONG_MIN - n)/base) {
118 if (val > (LONG_MAX - n)/base) {