~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to strings/my_strtoll10.c

MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
  properly handle a constant expression containing a mod operator
24
24
*/
25
25
#if defined(__NETWARE__) && defined(__MWERKS__) 
26
 
static ulonglong ulonglong_max= ~(ulonglong) 0;
27
 
#define ULONGLONG_MAX ulonglong_max
 
26
static uint64_t uint64_t_max= ~(uint64_t) 0;
 
27
#define ULONGLONG_MAX uint64_t_max
28
28
#else
29
 
#define ULONGLONG_MAX           (~(ulonglong) 0)
 
29
#define ULONGLONG_MAX           (~(uint64_t) 0)
30
30
#endif /* __NETWARE__ && __MWERKS__ */
31
 
#define MAX_NEGATIVE_NUMBER     ((ulonglong) 0x8000000000000000LL)
 
31
#define MAX_NEGATIVE_NUMBER     ((uint64_t) 0x8000000000000000LL)
32
32
#define INIT_CNT  9
33
33
#define LFACTOR   1000000000ULL
34
34
#define LFACTOR1  10000000000ULL
62
62
    will not read characters after *endptr.
63
63
 
64
64
  RETURN VALUES
65
 
    Value of string as a signed/unsigned longlong integer
 
65
    Value of string as a signed/unsigned int64_t integer
66
66
 
67
67
    if no error and endptr != NULL, it will be set to point at the character
68
68
    after the number
82
82
*/
83
83
 
84
84
 
85
 
longlong my_strtoll10(const char *nptr, char **endptr, int *error)
 
85
int64_t my_strtoll10(const char *nptr, char **endptr, int *error)
86
86
{
87
87
  const char *s, *end, *start, *n_end, *true_end;
88
88
  char *dummy;
89
89
  uchar c;
90
90
  unsigned long i, j, k;
91
 
  ulonglong li;
 
91
  uint64_t li;
92
92
  int negative;
93
93
  ulong cutoff, cutoff2, cutoff3;
94
94
 
207
207
  if (i > cutoff || (i == cutoff && ((j > cutoff2 || j == cutoff2) &&
208
208
                                     k > cutoff3)))
209
209
    goto overflow;
210
 
  li=i*LFACTOR2+ (ulonglong) j*100 + k;
211
 
  return (longlong) li;
 
210
  li=i*LFACTOR2+ (uint64_t) j*100 + k;
 
211
  return (int64_t) li;
212
212
 
213
213
overflow:                                       /* *endptr is set here */
214
214
  *error= MY_ERRNO_ERANGE;
215
 
  return negative ? LONGLONG_MIN : (longlong) ULONGLONG_MAX;
 
215
  return negative ? INT64_MIN: (int64_t) ULONGLONG_MAX;
216
216
 
217
217
end_i:
218
218
  *endptr= (char*) s;
219
 
  return (negative ? ((longlong) -(long) i) : (longlong) i);
 
219
  return (negative ? ((int64_t) -(long) i) : (int64_t) i);
220
220
 
221
221
end_i_and_j:
222
 
  li= (ulonglong) i * lfactor[(uint) (s-start)] + j;
 
222
  li= (uint64_t) i * lfactor[(uint) (s-start)] + j;
223
223
  *endptr= (char*) s;
224
 
  return (negative ? -((longlong) li) : (longlong) li);
 
224
  return (negative ? -((int64_t) li) : (int64_t) li);
225
225
 
226
226
end3:
227
 
  li=(ulonglong) i*LFACTOR+ (ulonglong) j;
 
227
  li=(uint64_t) i*LFACTOR+ (uint64_t) j;
228
228
  *endptr= (char*) s;
229
 
  return (negative ? -((longlong) li) : (longlong) li);
 
229
  return (negative ? -((int64_t) li) : (int64_t) li);
230
230
 
231
231
end4:
232
 
  li=(ulonglong) i*LFACTOR1+ (ulonglong) j * 10 + k;
 
232
  li=(uint64_t) i*LFACTOR1+ (uint64_t) j * 10 + k;
233
233
  *endptr= (char*) s;
234
234
  if (negative)
235
235
  {
236
236
   if (li > MAX_NEGATIVE_NUMBER)
237
237
     goto overflow;
238
 
   return -((longlong) li);
 
238
   return -((int64_t) li);
239
239
  }
240
 
  return (longlong) li;
 
240
  return (int64_t) li;
241
241
 
242
242
no_conv:
243
243
  /* There was no number to convert.  */