41 #include <my_global.h>
47 #define char_val(X) (X >= '0' && X <= '9' ? X-'0' :\
48 X >= 'A' && X <= 'Z' ? X-'A'+10 :\
49 X >= 'a' && X <= 'z' ? X-'a'+10 :\
52 char *str2int(
register const char *src,
register int radix,
long int lower,
53 long int upper,
long int *val)
71 if (radix < 2 || radix > 36) {
91 if ((limit = lower) > 0) limit = -
limit;
92 if ((scale = upper) > 0) scale = -scale;
93 if (scale < limit) limit = scale;
101 while (my_isspace(&my_charset_latin1,*src)) src++;
103 if (*src ==
'+') src++;
else
104 if (*src ==
'-') src++, sign = 1;
112 while (*src ==
'0') src++;
118 for (n = 0; (digits[
n]=char_val(*src)) < radix && n < 20; n++,src++) ;
140 for (sofar = 0, scale = -1; --n >= 1;)
142 if ((
long) -(d=digits[
n]) < limit) {
146 limit = (limit+d)/radix, sofar += d*scale; scale *= radix;
150 if ((
long) -(d=digits[
n]) < limit)
167 if (sofar < -LONG_MAX || (sofar= -sofar) > upper)
173 else if (sofar < lower)
187 int atoi(
const char *src)
190 str2int(src, 10, (
long) INT_MIN, (
long) INT_MAX, &val);
195 long atol(
const char *src)
198 str2int(src, 10, LONG_MIN, LONG_MAX, &val);