#include "m_ctype.h"#include "my_sys.h"#include <errno.h>Include dependency graph for strto.c:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Defines | |
| #define | UTYPE_MAX (ulong) ~0L |
| #define | TYPE_MIN LONG_MIN |
| #define | TYPE_MAX LONG_MAX |
| #define | longtype long |
| #define | ulongtype unsigned long |
| #define | function longtype strtol |
Functions | |
| function (const char *nptr, char **endptr, int base) | |
| function | ( | const char * | nptr, | |
| char ** | endptr, | |||
| int | base | |||
| ) |
Definition at line 85 of file strto.c.
References function, int(), longtype, my_charset_latin1, my_errno, my_isalpha, my_isdigit, my_isspace, my_toupper, NULL, TYPE_MAX, TYPE_MIN, ulongtype, and UTYPE_MAX.
00086 { 00087 int negative; 00088 register ulongtype cutoff; 00089 register unsigned int cutlim; 00090 register ulongtype i; 00091 register const char *s; 00092 register unsigned char c; 00093 const char *save; 00094 int overflow; 00095 00096 if (base < 0 || base == 1 || base > 36) 00097 base = 10; 00098 00099 s = nptr; 00100 00101 /* Skip white space. */ 00102 while (my_isspace(&my_charset_latin1, *s)) 00103 ++s; 00104 if (*s == '\0') 00105 { 00106 goto noconv; 00107 } 00108 00109 /* Check for a sign. */ 00110 negative= 0; 00111 if (*s == '-') 00112 { 00113 negative = 1; 00114 ++s; 00115 } 00116 else if (*s == '+') 00117 { 00118 ++s; 00119 } 00120 00121 00122 if (base == 16 && s[0] == '0' && my_toupper (&my_charset_latin1, s[1]) == 'X') 00123 s += 2; 00124 00125 /* If BASE is zero, figure it out ourselves. */ 00126 if (base == 0) 00127 { 00128 if (*s == '0') 00129 { 00130 if (my_toupper (&my_charset_latin1, s[1]) == 'X') 00131 { 00132 s += 2; 00133 base = 16; 00134 } 00135 else 00136 base = 8; 00137 } 00138 else 00139 base = 10; 00140 } 00141 00142 /* Save the pointer so we can check later if anything happened. */ 00143 save = s; 00144 00145 cutoff = UTYPE_MAX / (unsigned long int) base; 00146 cutlim = (uint) (UTYPE_MAX % (unsigned long int) base); 00147 00148 overflow = 0; 00149 i = 0; 00150 for (c = *s; c != '\0'; c = *++s) 00151 { 00152 if (my_isdigit (&my_charset_latin1, c)) 00153 c -= '0'; 00154 else if (my_isalpha (&my_charset_latin1, c)) 00155 c = my_toupper (&my_charset_latin1, c) - 'A' + 10; 00156 else 00157 break; 00158 if (c >= base) 00159 break; 00160 /* Check for overflow. */ 00161 if (i > cutoff || (i == cutoff && c > cutlim)) 00162 overflow = 1; 00163 else 00164 { 00165 i *= (ulongtype) base; 00166 i += c; 00167 } 00168 } 00169 00170 /* Check if anything actually happened. */ 00171 if (s == save) 00172 goto noconv; 00173 00174 /* Store in ENDPTR the address of one character 00175 past the last character we converted. */ 00176 if (endptr != NULL) 00177 *endptr = (char *) s; 00178 00179 #ifndef USE_UNSIGNED 00180 /* Check for a value that is within the range of 00181 `unsigned long int', but outside the range of `long int'. */ 00182 if (negative) 00183 { 00184 if (i > (ulongtype) TYPE_MIN) 00185 overflow = 1; 00186 } 00187 else if (i > (ulongtype) TYPE_MAX) 00188 overflow = 1; 00189 #endif 00190 00191 if (overflow) 00192 { 00193 my_errno=ERANGE; 00194 #ifdef USE_UNSIGNED 00195 return UTYPE_MAX; 00196 #else 00197 return negative ? TYPE_MIN : TYPE_MAX; 00198 #endif 00199 } 00200 00201 /* Return the result of the appropriate sign. */ 00202 return (negative ? -((longtype) i) : (longtype) i); 00203 00204 noconv: 00205 /* There was no number to convert. */ 00206 my_errno=EDOM; 00207 if (endptr != NULL) 00208 *endptr = (char *) nptr; 00209 return 0L; 00210 }
Here is the call graph for this function:

1.4.7

