~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mystrings/strto.cc

  • Committer: Brian Aker
  • Date: 2009-10-01 22:56:26 UTC
  • mto: (1154.1.1 staging)
  • mto: This revision was merged to the branch mainline in revision 1155.
  • Revision ID: brian@gaz-20091001225626-sb1pdykpxlnkheaj
Remove Factory/make scheduler work like everything else.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/*
17
17
  strtol,strtoul,strtoll,strtoull
18
 
  convert string to long, unsigned long, long long or unsigned long long.
 
18
  convert string to long, unsigned long, int64_t or uint64_t.
19
19
  strtoxx(char *src,char **ptr,int base)
20
20
  converts the string pointed to by src to an long of appropriate long and
21
21
  returnes it. It skips leading spaces and tabs (but not newlines, formfeeds,
40
40
   /* see 'strtoll.c' and 'strtoull.c' for the reasons */
41
41
#endif
42
42
 
43
 
#include "m_ctype.h"
44
 
#include "my_sys.h"                     /* defines errno */
45
 
#include <errno.h>
 
43
#include "mysys/mysys_priv.h"
46
44
 
47
45
#undef strtoull
48
46
#undef strtoll
49
47
#undef strtoul
50
48
#undef strtol
51
49
#ifdef USE_LONGLONG
52
 
#define UTYPE_MAX (~(uint64_t) 0)
53
50
#define TYPE_MIN LONGLONG_MIN
54
51
#define TYPE_MAX LONGLONG_MAX
55
52
#define longtype int64_t
60
57
#define function longtype strtoll
61
58
#endif
62
59
#else
63
 
#define UTYPE_MAX (ulong) ~0L
64
60
#define TYPE_MIN LONG_MIN
65
61
#define TYPE_MAX LONG_MAX
66
62
#define longtype long
88
84
  register unsigned int cutlim;
89
85
  register ulongtype i;
90
86
  register const char *s;
91
 
  register uchar c;
 
87
  register unsigned char c;
92
88
  const char *save;
93
89
  int overflow;
94
90
 
98
94
  s = nptr;
99
95
 
100
96
  /* Skip white space.  */
101
 
  while (my_isspace(&my_charset_latin1, *s))
 
97
  while (my_isspace(&my_charset_utf8_general_ci, *s))
102
98
    ++s;
103
99
  if (*s == '\0')
104
100
  {
116
112
  {
117
113
    ++s;
118
114
  }
119
 
    
120
 
 
121
 
  if (base == 16 && s[0] == '0' && my_toupper (&my_charset_latin1, s[1]) == 'X')
 
115
 
 
116
 
 
117
  if (base == 16 && s[0] == '0' && my_toupper (&my_charset_utf8_general_ci, s[1]) == 'X')
122
118
    s += 2;
123
119
 
124
120
  /* If BASE is zero, figure it out ourselves.  */
126
122
  {
127
123
    if (*s == '0')
128
124
    {
129
 
      if (my_toupper (&my_charset_latin1, s[1]) == 'X')
 
125
      if (my_toupper (&my_charset_utf8_general_ci, s[1]) == 'X')
130
126
      {
131
127
        s += 2;
132
128
        base = 16;
141
137
  /* Save the pointer so we can check later if anything happened.  */
142
138
  save = s;
143
139
 
144
 
  cutoff = UTYPE_MAX / (unsigned long int) base;
145
 
  cutlim = (uint) (UTYPE_MAX % (unsigned long int) base);
 
140
  cutoff = UINT64_MAX / (unsigned long int) base;
 
141
  cutlim = (uint32_t) (UINT64_MAX % (unsigned long int) base);
146
142
 
147
143
  overflow = 0;
148
144
  i = 0;
149
145
  for (c = *s; c != '\0'; c = *++s)
150
146
  {
151
 
    if (my_isdigit (&my_charset_latin1, c))
 
147
    if (my_isdigit (&my_charset_utf8_general_ci, c))
152
148
      c -= '0';
153
 
    else if (my_isalpha (&my_charset_latin1, c))
154
 
      c = my_toupper (&my_charset_latin1, c) - 'A' + 10;
 
149
    else if (my_isalpha (&my_charset_utf8_general_ci, c))
 
150
      c = my_toupper (&my_charset_utf8_general_ci, c) - 'A' + 10;
155
151
    else
156
152
      break;
157
153
    if (c >= base)
191
187
  {
192
188
    my_errno=ERANGE;
193
189
#ifdef USE_UNSIGNED
194
 
    return UTYPE_MAX;
 
190
    return UINT64_MAX;
195
191
#else
196
192
    return negative ? TYPE_MIN : TYPE_MAX;
197
193
#endif