diff --git a/reactos/lib/crt/stdlib/witoa.c b/reactos/lib/crt/stdlib/witoa.c index d9f414afb5e..a19630e2c69 100644 --- a/reactos/lib/crt/stdlib/witoa.c +++ b/reactos/lib/crt/stdlib/witoa.c @@ -13,49 +13,46 @@ /* * @implemented + * copy _i64toa from wine cvs 2006 month 05 day 21 */ char* _i64toa(__int64 value, char* string, int radix) { - char tmp[65]; - char *tp = tmp; - int i; - unsigned v; - int sign; - char *sp; + ULONGLONG val; + int negative; + char buffer[65]; + char *pos; + int digit; - if (radix > 36 || radix <= 1) - { - __set_errno(EDOM); - return 0; - } + if (value < 0 && radix == 10) { + negative = 1; + val = -value; + } else { + negative = 0; + val = value; + } /* if */ - sign = (radix == 10 && value < 0); - if (sign) - v = -value; - else - v = (unsigned)value; - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+'0'; - else - *tp++ = i + 'a' - 10; - } + pos = &buffer[64]; + *pos = '\0'; - if (string == 0) - string = (char *)malloc((tp-tmp)+sign+1); - sp = string; + do { + digit = val % radix; + val = val / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (val != 0L); - if (sign) - *sp++ = '-'; - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - return string; + if (negative) { + *--pos = '-'; + } /* if */ + + memcpy(string, pos, &buffer[64] - pos + 1); + return string; } + /* * @implemented */ diff --git a/reactos/lib/string/itoa.c b/reactos/lib/string/itoa.c index aed9a32ffd7..bf2e1ea0ca4 100644 --- a/reactos/lib/string/itoa.c +++ b/reactos/lib/string/itoa.c @@ -1,46 +1,47 @@ #include #include +#include /* * @implemented + * copy _i64toa from wine cvs 2006 month 05 day 21 */ char * _i64toa(__int64 value, char *string, int radix) { - char tmp[65]; - char *tp = tmp; - __int64 i; - unsigned __int64 v; - __int64 sign; - char *sp; + ULONGLONG val; + int negative; + char buffer[65]; + char *pos; + int digit; - if (radix > 36 || radix <= 1) - { - return 0; - } + if (value < 0 && radix == 10) { + negative = 1; + val = -value; + } else { + negative = 0; + val = value; + } /* if */ - sign = (radix == 10 && value < 0); - if (sign) - v = -value; - else - v = (unsigned __int64)value; - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+'0'; - else - *tp++ = i + 'a' - 10; - } + pos = &buffer[64]; + *pos = '\0'; - sp = string; - if (sign) - *sp++ = '-'; - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - return string; + do { + digit = val % radix; + val = val / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (val != 0L); + + if (negative) { + *--pos = '-'; + } /* if */ + + memcpy(string, pos, &buffer[64] - pos + 1); + return string; }