~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
1130.3.26 by Monty Taylor
Removed global.h from headers.
16
#include "drizzled/global.h"
1 by brian
clean slate
17
#include "m_string.h"
18
19
/*
20
  _dig_vec arrays are public because they are used in several outer places.
21
*/
22
char _dig_vec_upper[] =
23
  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
24
char _dig_vec_lower[] =
25
  "0123456789abcdefghijklmnopqrstuvwxyz";
26
27
28
/*
29
  Converts integer to its string representation in decimal notation.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
30
1 by brian
clean slate
31
  SYNOPSIS
32
    int10_to_str()
33
      val     - value to convert
34
      dst     - points to buffer where string representation should be stored
35
      radix   - flag that shows whenever val should be taken as signed or not
36
37
  DESCRIPTION
38
    This is version of int2str() function which is optimized for normal case
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
39
    of radix 10/-10. It takes only sign of radix parameter into account and
1 by brian
clean slate
40
    not its absolute value.
41
42
  RETURN VALUE
43
    Pointer to ending NUL character.
44
*/
45
492.1.9 by Monty
Fixed problem on 32-bit.
46
char *int10_to_str(int32_t val,char *dst,int radix)
1 by brian
clean slate
47
{
48
  char buffer[65];
49
  register char *p;
492.1.9 by Monty
Fixed problem on 32-bit.
50
  int32_t new_val;
51
  uint32_t uval = (uint32_t) val;
1 by brian
clean slate
52
53
  if (radix < 0)				/* -10 */
54
  {
55
    if (val < 0)
56
    {
57
      *dst++ = '-';
492.1.9 by Monty
Fixed problem on 32-bit.
58
      /* Avoid integer overflow in (-val) for INT32_MIN (BUG#31799). */
59
      uval = (uint32_t)0 - uval;
1 by brian
clean slate
60
    }
61
  }
62
63
  p = &buffer[sizeof(buffer)-1];
64
  *p = '\0';
492.1.9 by Monty
Fixed problem on 32-bit.
65
  new_val= (int32_t) (uval / 10);
66
  *--p = '0'+ (char) (uval - (uint32_t) new_val * 10);
1 by brian
clean slate
67
  val = new_val;
68
69
  while (val != 0)
70
  {
71
    new_val=val/10;
72
    *--p = '0' + (char) (val-new_val*10);
73
    val= new_val;
74
  }
75
  while ((*dst++ = *p++) != 0) ;
76
  return dst-1;
77
}