~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to strings/int2str.c

  • Committer: Monty Taylor
  • Date: 2008-07-22 05:48:51 UTC
  • mto: (202.1.3 toru)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: monty@inaugust.com-20080722054851-airxt73370725p7x
Re-enabled optimizations for the normal build, and added back the --with-debug option to turn them off. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
 
16
#include <my_global.h>
16
17
#include "m_string.h"
17
18
 
18
19
/*
45
46
    optimized int10_to_str() function.
46
47
 
47
48
  RETURN VALUE
48
 
    Pointer to ending NUL character or (char *)0 if radix is bad.
 
49
    Pointer to ending NUL character or NullS if radix is bad.
49
50
*/
50
51
  
51
52
char *
52
 
int2str(register int32_t val, register char *dst, register int radix, 
 
53
int2str(register long int val, register char *dst, register int radix, 
53
54
        int upcase)
54
55
{
55
56
  char buffer[65];
56
57
  register char *p;
57
58
  long int new_val;
58
59
  char *dig_vec= upcase ? _dig_vec_upper : _dig_vec_lower;
59
 
  unsigned long uval= (unsigned long) val;
 
60
  ulong uval= (ulong) val;
60
61
 
61
62
  if (radix < 0)
62
63
  {
63
64
    if (radix < -36 || radix > -2)
64
 
      return (char *)0;
 
65
      return NullS;
65
66
    if (val < 0)
66
67
    {
67
68
      *dst++ = '-';
68
69
      /* Avoid integer overflow in (-val) for LONGLONG_MIN (BUG#31799). */
69
 
      uval = (unsigned long)0 - uval;
 
70
      uval = (ulong)0 - uval;
70
71
    }
71
72
    radix = -radix;
72
73
  }
73
74
  else if (radix > 36 || radix < 2)
74
 
    return (char *)0;
 
75
    return NullS;
75
76
 
76
77
  /*
77
78
    The slightly contorted code which follows is due to the fact that
87
88
  */
88
89
  p = &buffer[sizeof(buffer)-1];
89
90
  *p = '\0';
90
 
  new_val= uval / (unsigned long) radix;
91
 
  *--p = dig_vec[(unsigned char) (uval- (unsigned long) new_val*(unsigned long) radix)];
 
91
  new_val= uval / (ulong) radix;
 
92
  *--p = dig_vec[(uchar) (uval- (ulong) new_val*(ulong) radix)];
92
93
  val = new_val;
93
94
#ifdef HAVE_LDIV
94
95
  while (val != 0)
102
103
  while (val != 0)
103
104
  {
104
105
    new_val=val/radix;
105
 
    *--p = dig_vec[(unsigned char) (val-new_val*radix)];
 
106
    *--p = dig_vec[(uchar) (val-new_val*radix)];
106
107
    val= new_val;
107
108
  }
108
109
#endif
129
130
    Pointer to ending NUL character.
130
131
*/
131
132
 
132
 
char *int10_to_str(int32_t val,char *dst,int radix)
 
133
char *int10_to_str(long int val,char *dst,int radix)
133
134
{
134
135
  char buffer[65];
135
136
  register char *p;
136
 
  int32_t new_val;
137
 
  uint32_t uval = (uint32_t) val;
 
137
  long int new_val;
 
138
  unsigned long int uval = (unsigned long int) val;
138
139
 
139
140
  if (radix < 0)                                /* -10 */
140
141
  {
141
142
    if (val < 0)
142
143
    {
143
144
      *dst++ = '-';
144
 
      /* Avoid integer overflow in (-val) for INT32_MIN (BUG#31799). */
145
 
      uval = (uint32_t)0 - uval;
 
145
      /* Avoid integer overflow in (-val) for LONGLONG_MIN (BUG#31799). */
 
146
      uval = (unsigned long int)0 - uval;
146
147
    }
147
148
  }
148
149
 
149
150
  p = &buffer[sizeof(buffer)-1];
150
151
  *p = '\0';
151
 
  new_val= (int32_t) (uval / 10);
152
 
  *--p = '0'+ (char) (uval - (uint32_t) new_val * 10);
 
152
  new_val= (long) (uval / 10);
 
153
  *--p = '0'+ (char) (uval - (unsigned long) new_val * 10);
153
154
  val = new_val;
154
155
 
155
156
  while (val != 0)