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