3 * - By John Hodge (thePowersGang)
6 * - strto[u][l]l/atoi implimentation
14 EXPORT unsigned long long strtoull(const char *str, char **end, int base)
18 if( !str || base < 0 || base > 36 || base == 1 ) {
25 // Trim leading spaces
26 while( isspace(*str) )
29 // Handle base detection for hex
30 if( base == 0 || base == 16 ) {
31 if( *str == '0' && str[1] == 'x' ) {
37 // Handle base detection for octal
38 if( base == 0 && *str == '0' ) {
43 // Fall back on decimal when unknown
51 if( '0' <= *str && *str <= '0'+base-1 )
55 if( '0' <= *str && *str <= '9' )
57 if( 'A' <= *str && *str <= 'A'+base-10-1 )
59 if( 'a' <= *str && *str <= 'a'+base-10-1 )
74 EXPORT unsigned long strtoul(const char *ptr, char **end, int base)
76 unsigned long long tmp = strtoull(ptr, end, base);
78 if( tmp > ULONG_MAX ) {
86 EXPORT long long strtoll(const char *str, char **end, int base)
89 unsigned long long ret;
96 while( isspace(*str) )
99 // Check for negative (or positive) sign
100 if(*str == '-' || *str == '+') {
105 ret = strtoull(str, end, base);
113 EXPORT long strtol(const char *str, char **end, int base)
115 long long tmp = strtoll(str, end, base);
116 if( tmp > LONG_MAX || tmp < LONG_MIN ) {
118 return (tmp > LONG_MAX) ? LONG_MAX : LONG_MIN;
124 * \fn EXPORT int atoi(const char *str)
125 * \brief Convert a string to an integer
127 EXPORT int atoi(const char *str)
129 long long tmp = strtoll(str, NULL, 0);
130 if( tmp > INT_MAX || tmp < INT_MIN ) {
132 return (tmp > INT_MAX) ? INT_MAX : INT_MIN;