10 |
* 2. Redistributions in binary form must reproduce the above copyright |
* 2. Redistributions in binary form must reproduce the above copyright |
11 |
* notice, this list of conditions and the following disclaimer in the |
* notice, this list of conditions and the following disclaimer in the |
12 |
* documentation and/or other materials provided with the distribution. |
* documentation and/or other materials provided with the distribution. |
13 |
* 3. All advertising materials mentioning features or use of this software |
* 3. [rescinded 22 July 1999] |
|
* must display the following acknowledgement: |
|
|
* This product includes software developed by the University of |
|
|
* California, Berkeley and its contributors. |
|
14 |
* 4. Neither the name of the University nor the names of its contributors |
* 4. Neither the name of the University nor the names of its contributors |
15 |
* may be used to endorse or promote products derived from this software |
* may be used to endorse or promote products derived from this software |
16 |
* without specific prior written permission. |
* without specific prior written permission. |
28 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
29 |
*/ |
*/ |
30 |
|
|
31 |
|
#ifdef HAVE_CONFIG_H |
32 |
|
#include "config.h" |
33 |
|
#endif |
34 |
|
#ifdef HAVE_LIMITS_H |
35 |
#include <limits.h> |
#include <limits.h> |
36 |
#include <ctype.h> |
#endif |
37 |
|
#ifdef HAVE_SYS_PARAM_H |
38 |
|
#include <sys/param.h> |
39 |
|
#endif |
40 |
#include <errno.h> |
#include <errno.h> |
41 |
|
#ifdef NEED_DECLARATION_ERRNO |
42 |
|
extern int errno; |
43 |
|
#endif |
44 |
#if 0 |
#if 0 |
45 |
#include <stdlib.h> |
#include <stdlib.h> |
46 |
#endif |
#endif |
47 |
#include "ansidecl.h" |
#include "ansidecl.h" |
48 |
|
#include "safe-ctype.h" |
49 |
|
|
50 |
#ifndef ULONG_MAX |
#ifndef ULONG_MAX |
51 |
#define ULONG_MAX ((unsigned long)(~0L)) /* 0xFFFFFFFF */ |
#define ULONG_MAX ((unsigned long)(~0L)) /* 0xFFFFFFFF */ |
74 |
*/ |
*/ |
75 |
do { |
do { |
76 |
c = *s++; |
c = *s++; |
77 |
} while (isspace(c)); |
} while (ISSPACE(c)); |
78 |
if (c == '-') { |
if (c == '-') { |
79 |
neg = 1; |
neg = 1; |
80 |
c = *s++; |
c = *s++; |
91 |
cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; |
cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; |
92 |
cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; |
cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; |
93 |
for (acc = 0, any = 0;; c = *s++) { |
for (acc = 0, any = 0;; c = *s++) { |
94 |
if (isdigit(c)) |
if (ISDIGIT(c)) |
95 |
c -= '0'; |
c -= '0'; |
96 |
else if (isalpha(c)) |
else if (ISALPHA(c)) |
97 |
c -= isupper(c) ? 'A' - 10 : 'a' - 10; |
c -= ISUPPER(c) ? 'A' - 10 : 'a' - 10; |
98 |
else |
else |
99 |
break; |
break; |
100 |
if (c >= base) |
if (c >= base) |
101 |
break; |
break; |
102 |
if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) |
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) |
103 |
any = -1; |
any = -1; |
104 |
else { |
else { |
105 |
any = 1; |
any = 1; |