~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to strings/str2int.c

  • Committer: Patrick Galbraith
  • Date: 2008-07-24 16:57:40 UTC
  • mto: (202.2.4 rename-mysql-to-drizzle)
  • mto: This revision was merged to the branch mainline in revision 212.
  • Revision ID: patg@ishvara-20080724165740-x58yw6zs6d9o17lf
Most everything working with client rename
mysqlslap test still fails... can't connect to the server

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
  The result is a pointer to the first character after the number;
23
23
  trailing spaces will NOT be skipped.
24
24
 
25
 
  If an error is detected, the result will be (char *)0, the value put
 
25
  If an error is detected, the result will be NullS, the value put
26
26
  in val will be 0, and errno will be set to
27
27
        EDOM    if there are no digits
28
28
        ERANGE  if the result would overflow or otherwise fail to lie
37
37
  call has no problems.
38
38
*/
39
39
 
 
40
#include <my_global.h>
40
41
#include "m_string.h"
41
42
#include "m_ctype.h"
 
43
#include "my_sys.h"                     /* defines errno */
42
44
#include <errno.h>
43
45
 
44
46
#define char_val(X) (X >= '0' && X <= '9' ? X-'0' :\
65
67
  /*  Check that the radix is in the range 2..36  */
66
68
  if (radix < 2 || radix > 36) {
67
69
    errno=EDOM;
68
 
    return (char *)0;
 
70
    return NullS;
69
71
  }
70
72
 
71
73
  /*  The basic problem is: how do we handle the conversion of
77
79
      machines all, if +|n| is representable, so is -|n|, but on
78
80
      twos complement machines the converse is not true.  So the
79
81
      "maximum" representable number has a negative representative.
80
 
      Limit is set to cmin(-|lower|,-|upper|); this is the "largest"
 
82
      Limit is set to min(-|lower|,-|upper|); this is the "largest"
81
83
      number we are concerned with.     */
82
84
 
83
85
  /*  Calculate Limit using Scale as a scratch variable  */
92
94
      converted value (and the scale!) as *negative* numbers,
93
95
      so the sign is the opposite of what you might expect.
94
96
      */
95
 
  while (my_isspace(&my_charset_utf8_general_ci,*src)) src++;
 
97
  while (my_isspace(&my_charset_latin1,*src)) src++;
96
98
  sign = -1;
97
99
  if (*src == '+') src++; else
98
100
    if (*src == '-') src++, sign = 1;
115
117
 
116
118
  if (start == src) {
117
119
    errno=EDOM;
118
 
    return (char *)0;
 
120
    return NullS;
119
121
  }
120
122
 
121
123
  /*  The invariant we want to maintain is that src is just
135
137
  {
136
138
    if ((long) -(d=digits[n]) < limit) {
137
139
      errno=ERANGE;
138
 
      return (char *)0;
 
140
      return NullS;
139
141
    }
140
142
    limit = (limit+d)/radix, sofar += d*scale; scale *= radix;
141
143
  }
144
146
    if ((long) -(d=digits[n]) < limit)          /* get last digit */
145
147
    {
146
148
      errno=ERANGE;
147
 
      return (char *)0;
 
149
      return NullS;
148
150
    }
149
151
    sofar+=d*scale;
150
152
  }
161
163
    if (sofar < -LONG_MAX || (sofar= -sofar) > upper)
162
164
    {
163
165
      errno=ERANGE;
164
 
      return (char *)0;
 
166
      return NullS;
165
167
    }
166
168
  }
167
169
  else if (sofar < lower)
168
170
  {
169
171
    errno=ERANGE;
170
 
    return (char *)0;
 
172
    return NullS;
171
173
  }
172
174
  *val = sofar;
173
175
  errno=0;                      /* indicate that all went well */