245cbbeaa833d1aa42f339b185a83bf0d0727641
[reactos.git] / lib / crtdll / stdlib / itoa.c
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS system libraries
4  * FILE:        lib/crtdll/stdlib/itoa.c
5  * PURPOSE:     converts a integer to ascii
6  * PROGRAMER:   
7  * UPDATE HISTORY:
8  *              1995: Created
9  *              1998: Added ltoa Boudewijn Dekker
10  */
11 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
12
13 #include <msvcrt/errno.h>
14 #include <msvcrt/stdlib.h>
15 #include <msvcrt/internal/file.h>
16
17
18 /*
19  * @implemented
20  *
21  * this function is now forwarded to NTDLL._itoa to reduce code duplication
22  */
23 #if 0
24 char* _itoa(int value, char* string, int radix)
25 {
26   char tmp[33];
27   char *tp = tmp;
28   int i;
29   unsigned v;
30   int sign;
31   char *sp;
32
33   if (radix > 36 || radix <= 1)
34   {
35     __set_errno(EDOM);
36     return 0;
37   }
38
39   sign = (radix == 10 && value < 0);
40   if (sign)
41     v = -value;
42   else
43     v = (unsigned)value;
44   while (v || tp == tmp)
45   {
46     i = v % radix;
47     v = v / radix;
48     if (i < 10)
49       *tp++ = i+'0';
50     else
51       *tp++ = i + 'a' - 10;
52   }
53
54   if (string == 0)
55     string = (char *)malloc((tp-tmp)+sign+1);
56   sp = string;
57
58   if (sign)
59     *sp++ = '-';
60   while (tp > tmp)
61     *sp++ = *--tp;
62   *sp = 0;
63   return string;
64 }
65 #endif
66
67 /*
68  * @implemented
69  *
70  * this function is now forwarded to NTDLL._ltoa to reduce code duplication
71  */
72 #if 0
73 char* _ltoa(long value, char* string, int radix)
74 {
75   char tmp[33];
76   char *tp = tmp;
77   long i;
78   unsigned long v;
79   int sign;
80   char *sp;
81
82   if (radix > 36 || radix <= 1)
83   {
84      __set_errno(EDOM);
85     return 0;
86   }
87
88   sign = (radix == 10 && value < 0);
89   if (sign)
90     v = -value;
91   else
92     v = (unsigned long)value;
93   while (v || tp == tmp)
94   {
95     i = v % radix;
96     v = v / radix;
97     if (i < 10)
98       *tp++ = i+'0';
99     else
100       *tp++ = i + 'a' - 10;
101   }
102
103   if (string == 0)
104     string = (char *)malloc((tp-tmp)+sign+1);
105   sp = string;
106
107   if (sign)
108     *sp++ = '-';
109   while (tp > tmp)
110     *sp++ = *--tp;
111   *sp = 0;
112   return string;
113 }
114 #endif
115
116 /*
117  * @implemented
118  *
119  * this function is now forwarded to NTDLL._ultoa to reduce code duplication
120  */
121 #if 0
122 char* _ultoa(unsigned long value, char* string, int radix)
123 {
124   char tmp[33];
125   char *tp = tmp;
126   long i;
127   unsigned long v = value;
128   char *sp;
129
130   if (radix > 36 || radix <= 1)
131   {
132     __set_errno(EDOM);
133     return 0;
134   }
135
136   while (v || tp == tmp)
137   {
138     i = v % radix;
139     v = v / radix;
140     if (i < 10)
141       *tp++ = i+'0';
142     else
143       *tp++ = i + 'a' - 10;
144   }
145
146   if (string == 0)
147     string = (char *)malloc((tp-tmp)+1);
148   sp = string;
149
150   while (tp > tmp)
151     *sp++ = *--tp;
152   *sp = 0;
153   return string;
154 }
155 #endif