1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS system libraries 4 * FILE: lib/sdk/crt/string/witow.c 5 * PURPOSE: converts a integer to wchar_t 6 * PROGRAMER: 7 * UPDATE HISTORY: 8 * 1995: Created 9 * 1998: Added ltoa by Ariadne 10 * 2000: derived from ./itoa.c by ea 11 */ 12 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ 13 14 #include <precomp.h> 15 16 /* 17 * @implemented 18 */ 19 wchar_t* _i64tow(__int64 value, wchar_t* string, int radix) 20 { 21 wchar_t tmp[65]; 22 wchar_t* tp = tmp; 23 int i; 24 unsigned v; 25 int sign; 26 wchar_t* sp; 27 28 if (radix > 36 || radix <= 1) { 29 _set_errno(EDOM); 30 return 0; 31 } 32 33 sign = (radix == 10 && value < 0); 34 if (sign) 35 v = -value; 36 else 37 v = (unsigned)value; 38 while (v || tp == tmp) { 39 i = v % radix; 40 v = v / radix; 41 if (i < 10) 42 *tp++ = i+L'0'; 43 else 44 *tp++ = i + L'a' - 10; 45 } 46 47 if (string == 0) 48 string = (wchar_t*)malloc(((tp-tmp)+sign+1)*sizeof(wchar_t)); 49 sp = string; 50 51 if (sign) 52 *sp++ = L'-'; 53 while (tp > tmp) 54 *sp++ = *--tp; 55 *sp = 0; 56 return string; 57 } 58 59 /* 60 * @implemented 61 */ 62 wchar_t* _ui64tow(unsigned __int64 value, wchar_t* string, int radix) 63 { 64 wchar_t tmp[65]; 65 wchar_t* tp = tmp; 66 long i; 67 unsigned long v = value; 68 wchar_t* sp; 69 70 if (radix > 36 || radix <= 1) { 71 _set_errno(EDOM); 72 return 0; 73 } 74 75 while (v || tp == tmp) { 76 i = v % radix; 77 v = v / radix; 78 if (i < 10) 79 *tp++ = i+L'0'; 80 else 81 *tp++ = i + L'a' - 10; 82 } 83 84 if (string == 0) 85 string = (wchar_t*)malloc(((tp-tmp)+1)*sizeof(wchar_t)); 86 sp = string; 87 88 while (tp > tmp) 89 *sp++ = *--tp; 90 *sp = 0; 91 return string; 92 } 93