4 #if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE)
8 /* Convert a possibly signed character to a nonnegative int */
9 /* XXX This assumes characters are 8 bits wide */
10 #ifdef __CHAR_UNSIGNED__
11 #define Py_CHARMASK(c) (c)
13 #define Py_CHARMASK(c) ((c) & 0xff)
16 /* strtol and strtoul, renamed to avoid conflicts */
20 ** This is a general purpose routine for converting
21 ** an ascii string to an integer in an arbitrary base.
22 ** Leading white space is ignored. If 'base' is zero
23 ** it looks for a leading 0, 0x or 0X to tell which
24 ** base. If these are absent it defaults to 10.
25 ** Base must be 0 or between 2 and 36 (inclusive).
26 ** If 'ptr' is non-NULL it will contain a pointer to
27 ** the end of the scan.
28 ** Errors due to bad pointers will probably result in
29 ** exceptions - we don't check for them.
33 #ifndef DONT_HAVE_ERRNO_H
38 PyOS_strtoul(register char *str
, char **ptr
, int base
)
40 register unsigned long result
; /* return value of the function */
41 register int c
; /* current input character */
42 register unsigned long temp
; /* used in overflow testing */
43 int ovf
; /* true if overflow occurred */
48 /* catch silly bases */
49 if (base
!= 0 && (base
< 2 || base
> 36))
56 /* skip leading white space */
57 while (*str
&& isspace(Py_CHARMASK(*str
)))
60 /* check for leading 0 or 0x for auto-base or base 16 */
63 case 0: /* look for leading 0, 0x or 0X */
67 if (*str
== 'x' || *str
== 'X')
79 case 16: /* skip leading 0x or 0X */
80 if (*str
== '0' && (*(str
+1) == 'x' || *(str
+1) == 'X'))
85 /* do the conversion */
86 while ((c
= Py_CHARMASK(*str
)) != '\0')
88 if (isdigit(c
) && c
- '0' < base
)
94 if (c
>= 'a' && c
<= 'z')
96 else /* non-"digit" character */
98 if (c
>= base
) /* non-"digit" character */
102 result
= result
* base
+ c
;
105 if(((long)(result
- c
) / base
!= (long)temp
)) /* overflow */
109 if ((result
- c
) / base
!= temp
) /* overflow */
116 /* set pointer to point to the last character scanned */
121 result
= (unsigned long) ~0L;
128 PyOS_strtol(char *str
, char **ptr
, int base
)
133 while (*str
&& isspace(Py_CHARMASK(*str
)))
137 if (sign
== '+' || sign
== '-')
140 result
= (long) PyOS_strtoul(str
, ptr
, base
);
142 /* Signal overflow if the result appears negative,
143 except for the largest negative integer */
144 if (result
< 0 && !(sign
== '-' && result
== -result
)) {