~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mystrings/int2str.cc

  • Committer: Brian Aker
  • Date: 2008-12-16 07:07:50 UTC
  • Revision ID: brian@tangent.org-20081216070750-o5ykltxxqvn2awrx
Fixed errors test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
/*
28
28
  Convert integer to its string representation in given scale of notation.
29
 
   
 
29
 
30
30
  SYNOPSIS
31
31
    int2str()
32
32
      val     - value to convert
35
35
      upcase  - set to 1 if we should use upper-case digits
36
36
 
37
37
  DESCRIPTION
38
 
    Converts the (long) integer value to its character form and moves it to 
39
 
    the destination buffer followed by a terminating NUL. 
 
38
    Converts the (long) integer value to its character form and moves it to
 
39
    the destination buffer followed by a terminating NUL.
40
40
    If radix is -2..-36, val is taken to be SIGNED, if radix is  2..36, val is
41
 
    taken to be UNSIGNED. That is, val is signed if and only if radix is. 
 
41
    taken to be UNSIGNED. That is, val is signed if and only if radix is.
42
42
    All other radixes treated as bad and nothing will be changed in this case.
43
43
 
44
44
    For conversion to decimal representation (radix is -10 or 10) one can use
47
47
  RETURN VALUE
48
48
    Pointer to ending NUL character or (char *)0 if radix is bad.
49
49
*/
50
 
  
 
50
 
51
51
char *
52
 
int2str(register long int val, register char *dst, register int radix, 
 
52
int2str(register int32_t val, register char *dst, register int radix,
53
53
        int upcase)
54
54
{
55
55
  char buffer[65];
113
113
 
114
114
/*
115
115
  Converts integer to its string representation in decimal notation.
116
 
   
 
116
 
117
117
  SYNOPSIS
118
118
    int10_to_str()
119
119
      val     - value to convert
122
122
 
123
123
  DESCRIPTION
124
124
    This is version of int2str() function which is optimized for normal case
125
 
    of radix 10/-10. It takes only sign of radix parameter into account and 
 
125
    of radix 10/-10. It takes only sign of radix parameter into account and
126
126
    not its absolute value.
127
127
 
128
128
  RETURN VALUE
129
129
    Pointer to ending NUL character.
130
130
*/
131
131
 
132
 
char *int10_to_str(long int val,char *dst,int radix)
 
132
char *int10_to_str(int32_t val,char *dst,int radix)
133
133
{
134
134
  char buffer[65];
135
135
  register char *p;
136
 
  long int new_val;
137
 
  unsigned long int uval = (unsigned long int) val;
 
136
  int32_t new_val;
 
137
  uint32_t uval = (uint32_t) val;
138
138
 
139
139
  if (radix < 0)                                /* -10 */
140
140
  {
141
141
    if (val < 0)
142
142
    {
143
143
      *dst++ = '-';
144
 
      /* Avoid integer overflow in (-val) for LONGLONG_MIN (BUG#31799). */
145
 
      uval = (unsigned long int)0 - uval;
 
144
      /* Avoid integer overflow in (-val) for INT32_MIN (BUG#31799). */
 
145
      uval = (uint32_t)0 - uval;
146
146
    }
147
147
  }
148
148
 
149
149
  p = &buffer[sizeof(buffer)-1];
150
150
  *p = '\0';
151
 
  new_val= (long) (uval / 10);
152
 
  *--p = '0'+ (char) (uval - (unsigned long) new_val * 10);
 
151
  new_val= (int32_t) (uval / 10);
 
152
  *--p = '0'+ (char) (uval - (uint32_t) new_val * 10);
153
153
  val = new_val;
154
154
 
155
155
  while (val != 0)