3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/msvcrt/stdlib/itow.c
6 * PURPOSE: converts a integer to wchar_t
10 * 1998: Added ltoa Boudewijn Dekker
11 * 2000: derived from ./itoa.c by ea
13 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
15 #include <msvcrt/errno.h>
16 #include <msvcrt/stdlib.h>
17 #include <msvcrt/internal/file.h>
23 wchar_t* _itow(int value, wchar_t* string, int radix)
32 if (radix > 36 || radix <= 1)
38 sign = ((radix == 10) && (value < 0));
44 while (v || tp == tmp) {
48 *tp++ = i+ (wchar_t) '0';
50 *tp++ = i + (wchar_t) 'a' - 10;
55 string = (wchar_t*) malloc((tp-tmp) + (sign + 1) * sizeof(wchar_t));
60 *sp++ = (wchar_t) '-';
72 wchar_t* _ltow(long value, wchar_t* string, int radix)
81 if (radix > 36 || radix <= 1) {
86 sign = ((radix == 10) && (value < 0));
90 v = (unsigned long) value;
92 while (v || tp == tmp) {
96 *tp++ = i + (wchar_t) '0';
98 *tp++ = i + (wchar_t) 'a' - 10;
103 string = (wchar_t*) malloc((tp - tmp) + (sign + 1) * sizeof(wchar_t));
108 *sp++ = (wchar_t) '-';
120 wchar_t* _ultow(unsigned long value, wchar_t* string, int radix)
125 unsigned long int v = value;
128 if (radix > 36 || radix <= 1) {
132 while (v || tp == tmp) {
136 *tp++ = i + (wchar_t) '0';
138 *tp++ = i + (wchar_t) 'a' - 10;
143 #ifdef _MSVCRT_LIB_ // TODO: check on difference?
144 string = (wchar_t*)malloc(((tp-tmp)+1)*sizeof(wchar_t));
145 #else // TODO: FIXME: review which is correct
146 string = (wchar_t*)malloc((tp - tmp) + sizeof(wchar_t));
147 #endif /*_MSVCRT_LIB_*/