diff --git a/reactos/lib/crt/stdlib/itoa.c b/reactos/lib/crt/stdlib/itoa.c index bb2c5e81d08..4097fc400c8 100644 --- a/reactos/lib/crt/stdlib/itoa.c +++ b/reactos/lib/crt/stdlib/itoa.c @@ -104,37 +104,32 @@ char* _ltoa(long value, char* string, int radix) /* * @implemented + * copy it from wine 0.9.0 with small modifcations do check for NULL */ -char* _ultoa(unsigned long value, char* string, int radix) +char* ultoa(unsigned long value, char* string, int radix) { - char tmp[33]; - char* tp = tmp; - long i; - unsigned long v = value; - char* sp; + char buffer[33]; + char *pos; + int digit; + + pos = &buffer[32]; + *pos = '\0'; - if (radix > 36 || radix <= 1) - { - __set_errno(EDOM); - return 0; - } + if (string == NULL) + { + return NULL; + } + + do { + digit = value % radix; + value = value / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (value != 0L); - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+'0'; - else - *tp++ = i + 'a' - 10; - } - - if (string == 0) - string = (char*)malloc((tp-tmp)+1); - sp = string; - - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - return string; + memcpy(string, pos, &buffer[32] - pos + 1); + return string; } diff --git a/reactos/lib/string/itoa.c b/reactos/lib/string/itoa.c index 3bcb9cb2321..aed9a32ffd7 100644 --- a/reactos/lib/string/itoa.c +++ b/reactos/lib/string/itoa.c @@ -133,35 +133,35 @@ _ltoa(long value, char *string, int radix) /* - * @implemented + * @implemented + * copy it from wine 0.9.0 with small modifcations do check for NULL */ char * _ultoa(unsigned long value, char *string, int radix) { - char tmp[33]; - char *tp = tmp; - long i; - unsigned long v = value; - char *sp; + char buffer[33]; + char *pos; + int digit; + + pos = &buffer[32]; + *pos = '\0'; - if (radix > 36 || radix <= 1) - { - return 0; - } + if (string == NULL) + { + return NULL; + } + + do { + digit = value % radix; + value = value / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (value != 0L); - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+'0'; - else - *tp++ = i + 'a' - 10; - } - - sp = string; - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - return string; + memcpy(string, pos, &buffer[32] - pos + 1); + + return string; }