17 #include <drizzled/internal/m_string.h>
25 #define MAX_NEGATIVE_NUMBER ((uint64_t) 0x8000000000000000LL)
27 #define LFACTOR 1000000000ULL
28 #define LFACTOR1 10000000000ULL
29 #define LFACTOR2 100000000000ULL
31 static uint64_t lfactor[9]=
33 1L, 10L, 100L, 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L
79 int64_t my_strtoll10(
const char *nptr,
char **endptr,
int *error)
81 const char *s, *end, *start, *n_end, *true_end;
84 unsigned long i, j, k;
87 uint64_t cutoff, cutoff2, cutoff3;
94 while (s != end && (*s ==
' ' || *s ==
'\t'))
102 while (*s ==
' ' || *s ==
'\t')
118 cutoff= MAX_NEGATIVE_NUMBER / LFACTOR2;
119 cutoff2= (MAX_NEGATIVE_NUMBER % LFACTOR2) / 100;
120 cutoff3= MAX_NEGATIVE_NUMBER % 100;
130 cutoff= UINT64_MAX / LFACTOR2;
131 cutoff2= UINT64_MAX % LFACTOR2 / 100;
132 cutoff3= UINT64_MAX % 100;
150 if ((c= (*s-
'0')) > 9)
153 n_end= ++s+ INIT_CNT-1;
159 for (; s != n_end ; s++)
161 if ((c= (*s-
'0')) > 9)
171 n_end= true_end= s + INIT_CNT;
176 if ((c= (*s-
'0')) > 9)
179 }
while (++s != n_end);
186 if ((c= (*s-
'0')) > 9)
191 if (++s == end || (c= (*s-
'0')) > 9)
194 *endptr= (
char*) ++s;
197 if (s != end && (c= (*s-
'0')) <= 9)
201 if (i > cutoff || (i == cutoff && ((j > cutoff2 || j == cutoff2) &&
204 li=i*LFACTOR2+ (uint64_t) j*100 + k;
209 return negative ? INT64_MIN: INT64_MAX;
213 return (negative ? ((int64_t) -(long) i) : (int64_t) i);
216 li= (uint64_t) i * lfactor[(
unsigned int) (s-start)] + j;
218 return (negative ? -((int64_t) li) : (int64_t) li);
221 li=(uint64_t) i*LFACTOR+ (uint64_t) j;
223 return (negative ? -((int64_t) li) : (int64_t) li);
226 li=(uint64_t) i*LFACTOR1+ (uint64_t) j * 10 + k;
230 if (li > MAX_NEGATIVE_NUMBER)
232 return -((int64_t) li);
239 *endptr= (
char *) nptr;
TODO: Rename this file - func.h is stupid.