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
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 * this function is now forwarded to NTDLL._itow to reduce code duplication
26 wchar_t* _itow(int value
, wchar_t* string
, int radix
)
35 if (radix
> 36 || radix
<= 1)
41 sign
= ((radix
== 10) && (value
< 0));
47 while (v
|| tp
== tmp
) {
51 *tp
++ = i
+ (wchar_t) '0';
53 *tp
++ = i
+ (wchar_t) 'a' - 10;
58 string
= (wchar_t *) malloc((tp
-tmp
) + (sign
+ 1) * sizeof(wchar_t));
63 *sp
++ = (wchar_t) '-';
76 * this function is now forwarded to NTDLL._ltow to reduce code duplication
79 wchar_t* _ltow(long value
, wchar_t* string
, int radix
)
88 if (radix
> 36 || radix
<= 1) {
93 sign
= ((radix
== 10) && (value
< 0));
97 v
= (unsigned long) value
;
99 while (v
|| tp
== tmp
) {
103 *tp
++ = i
+ (wchar_t) '0';
105 *tp
++ = i
+ (wchar_t) 'a' - 10;
110 string
= (wchar_t *) malloc((tp
- tmp
) + (sign
+ 1) * sizeof(wchar_t));
115 *sp
++ = (wchar_t) '-';
128 * this function is now forwarded to NTDLL._ultow to reduce code duplication
131 wchar_t* _ultow(unsigned long value
, wchar_t* string
, int radix
)
136 unsigned long int v
= value
;
139 if (radix
> 36 || radix
<= 1) {
143 while (v
|| tp
== tmp
) {
147 *tp
++ = i
+ (wchar_t) '0';
149 *tp
++ = i
+ (wchar_t) 'a' - 10;
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_*/