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>
20 wchar_t* _itow(int value, wchar_t* string, int radix)
29 if (radix > 36 || radix <= 1)
35 sign = ((radix == 10) && (value < 0));
41 while (v || tp == tmp) {
45 *tp++ = i+ (wchar_t) '0';
47 *tp++ = i + (wchar_t) 'a' - 10;
52 string = (wchar_t*) malloc((tp-tmp) + (sign + 1) * sizeof(wchar_t));
57 *sp++ = (wchar_t) '-';
66 wchar_t* _ltow(long value, wchar_t* string, int radix)
75 if (radix > 36 || radix <= 1) {
80 sign = ((radix == 10) && (value < 0));
84 v = (unsigned long) value;
86 while (v || tp == tmp) {
90 *tp++ = i + (wchar_t) '0';
92 *tp++ = i + (wchar_t) 'a' - 10;
97 string = (wchar_t*) malloc((tp - tmp) + (sign + 1) * sizeof(wchar_t));
102 *sp++ = (wchar_t) '-';
111 wchar_t* _ultow(unsigned long value, wchar_t* string, int radix)
116 unsigned long int v = value;
119 if (radix > 36 || radix <= 1) {
123 while (v || tp == tmp) {
127 *tp++ = i + (wchar_t) '0';
129 *tp++ = i + (wchar_t) 'a' - 10;
134 #ifdef _MSVCRT_LIB_ // TODO: check on difference?
135 string = (wchar_t*)malloc(((tp-tmp)+1)*sizeof(wchar_t));
136 #else // TODO: FIXME: review which is correct
137 string = (wchar_t*)malloc((tp - tmp) + sizeof(wchar_t));
138 #endif /*_MSVCRT_LIB_*/