~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mystrings/str2int.c

  • Committer: Monty Taylor
  • Date: 2008-10-08 01:10:45 UTC
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: monty@inaugust.com-20081008011045-zqozbc81f8qhmxok
Get rid of pragma interface/pragma implementation.

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