~ubuntu-branches/ubuntu/intrepid/ecl/intrepid

« back to all changes in this revision

Viewing changes to src/gmp/mpz/get_str.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Van Eynde
  • Date: 2007-04-09 11:51:51 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070409115151-ql8cr0kalzx1jmla
Tags: 0.9i-20070324-2
Upload to unstable. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
   result.  If STRING is not NULL, the caller must ensure enough space is
5
5
   available to store the result.
6
6
 
7
 
Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2002 Free Software Foundation,
8
 
Inc.
 
7
Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2002, 2005 Free Software
 
8
Foundation, Inc.
9
9
 
10
10
This file is part of the GNU MP Library.
11
11
 
21
21
 
22
22
You should have received a copy of the GNU Lesser General Public License
23
23
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
24
 
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25
 
MA 02111-1307, USA. */
 
24
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
25
MA 02110-1301, USA. */
26
26
 
27
27
#include <string.h> /* for strlen */
28
28
#include "gmp.h"
40
40
  size_t alloc_size = 0;
41
41
  char *num_to_text;
42
42
  int i;
43
 
  TMP_DECL (marker);
 
43
  TMP_DECL;
44
44
 
45
45
  if (base >= 0)
46
46
    {
 
47
      num_to_text = "0123456789abcdefghijklmnopqrstuvwxyz";
47
48
      if (base == 0)
48
49
        base = 10;
49
 
      num_to_text = "0123456789abcdefghijklmnopqrstuvwxyz";
 
50
      else if (base > 36)
 
51
        {
 
52
          num_to_text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 
53
          if (base > 62)
 
54
            return NULL;
 
55
        }
50
56
    }
51
57
  else
52
58
    {
71
77
    }
72
78
 
73
79
  /* mpn_get_str clobbers its input on non power-of-2 bases */
74
 
  TMP_MARK (marker);
 
80
  TMP_MARK;
75
81
  xp = x->_mp_d;
76
82
  if (! POW2_P (base))
77
83
    {
97
103
    res_str[i] = num_to_text[str[i]];
98
104
  res_str[str_size] = 0;
99
105
 
100
 
  TMP_FREE (marker);
 
106
  TMP_FREE;
101
107
 
102
108
  /* if allocated then resize down to the actual space required */
103
109
  if (alloc_size != 0)