~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mystrings/strto.c

  • Committer: Mark Atwood
  • Date: 2008-10-16 11:33:16 UTC
  • mto: (520.1.13 drizzle)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: mark@fallenpegasus.com-20081016113316-ff6jdt31ck90sjdh
an implemention of the errmsg plugin

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,
49
49
#undef strtoul
50
50
#undef strtol
51
51
#ifdef USE_LONGLONG
52
 
#define UTYPE_MAX (~(uint64_t) 0)
53
52
#define TYPE_MIN LONGLONG_MIN
54
53
#define TYPE_MAX LONGLONG_MAX
55
54
#define longtype int64_t
60
59
#define function longtype strtoll
61
60
#endif
62
61
#else
63
 
#define UTYPE_MAX (ulong) ~0L
64
62
#define TYPE_MIN LONG_MIN
65
63
#define TYPE_MAX LONG_MAX
66
64
#define longtype long
88
86
  register unsigned int cutlim;
89
87
  register ulongtype i;
90
88
  register const char *s;
91
 
  register uchar c;
 
89
  register unsigned char c;
92
90
  const char *save;
93
91
  int overflow;
94
92
 
98
96
  s = nptr;
99
97
 
100
98
  /* Skip white space.  */
101
 
  while (my_isspace(&my_charset_latin1, *s))
 
99
  while (my_isspace(&my_charset_utf8_general_ci, *s))
102
100
    ++s;
103
101
  if (*s == '\0')
104
102
  {
118
116
  }
119
117
    
120
118
 
121
 
  if (base == 16 && s[0] == '0' && my_toupper (&my_charset_latin1, s[1]) == 'X')
 
119
  if (base == 16 && s[0] == '0' && my_toupper (&my_charset_utf8_general_ci, s[1]) == 'X')
122
120
    s += 2;
123
121
 
124
122
  /* If BASE is zero, figure it out ourselves.  */
126
124
  {
127
125
    if (*s == '0')
128
126
    {
129
 
      if (my_toupper (&my_charset_latin1, s[1]) == 'X')
 
127
      if (my_toupper (&my_charset_utf8_general_ci, s[1]) == 'X')
130
128
      {
131
129
        s += 2;
132
130
        base = 16;
141
139
  /* Save the pointer so we can check later if anything happened.  */
142
140
  save = s;
143
141
 
144
 
  cutoff = UTYPE_MAX / (unsigned long int) base;
145
 
  cutlim = (uint) (UTYPE_MAX % (unsigned long int) base);
 
142
  cutoff = UINT64_MAX / (unsigned long int) base;
 
143
  cutlim = (uint) (UINT64_MAX % (unsigned long int) base);
146
144
 
147
145
  overflow = 0;
148
146
  i = 0;
149
147
  for (c = *s; c != '\0'; c = *++s)
150
148
  {
151
 
    if (my_isdigit (&my_charset_latin1, c))
 
149
    if (my_isdigit (&my_charset_utf8_general_ci, c))
152
150
      c -= '0';
153
 
    else if (my_isalpha (&my_charset_latin1, c))
154
 
      c = my_toupper (&my_charset_latin1, c) - 'A' + 10;
 
151
    else if (my_isalpha (&my_charset_utf8_general_ci, c))
 
152
      c = my_toupper (&my_charset_utf8_general_ci, c) - 'A' + 10;
155
153
    else
156
154
      break;
157
155
    if (c >= base)
191
189
  {
192
190
    my_errno=ERANGE;
193
191
#ifdef USE_UNSIGNED
194
 
    return UTYPE_MAX;
 
192
    return UINT64_MAX;
195
193
#else
196
194
    return negative ? TYPE_MIN : TYPE_MAX;
197
195
#endif