~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to strings/strto.c

  • Committer: Monty Taylor
  • Date: 2008-07-01 14:33:36 UTC
  • mto: (28.1.12 backport_patch)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: monty@inaugust.com-20080701143336-8uihm7dhpu92rt0q
Somehow missed moving password.c. Duh.

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