Fixing a i64ltoa bug, replacing both version with wine, copy the code from wine cvs 2005-05-21, bug report by wine test

svn path=/trunk/; revision=21973
This commit is contained in:
Magnus Olsen 2006-05-21 20:26:51 +00:00
parent c94db29865
commit f340ab0a45
2 changed files with 63 additions and 65 deletions

View file

@ -13,49 +13,46 @@
/* /*
* @implemented * @implemented
* copy _i64toa from wine cvs 2006 month 05 day 21
*/ */
char* _i64toa(__int64 value, char* string, int radix) char* _i64toa(__int64 value, char* string, int radix)
{ {
char tmp[65]; ULONGLONG val;
char *tp = tmp; int negative;
int i; char buffer[65];
unsigned v; char *pos;
int sign; int digit;
char *sp;
if (radix > 36 || radix <= 1) if (value < 0 && radix == 10) {
{ negative = 1;
__set_errno(EDOM); val = -value;
return 0; } else {
} negative = 0;
val = value;
} /* if */
sign = (radix == 10 && value < 0); pos = &buffer[64];
if (sign) *pos = '\0';
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;
}
if (string == 0) do {
string = (char *)malloc((tp-tmp)+sign+1); digit = val % radix;
sp = string; val = val / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (val != 0L);
if (sign) if (negative) {
*sp++ = '-'; *--pos = '-';
while (tp > tmp) } /* if */
*sp++ = *--tp;
*sp = 0; memcpy(string, pos, &buffer[64] - pos + 1);
return string; return string;
} }
/* /*
* @implemented * @implemented
*/ */

View file

@ -1,46 +1,47 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <windows.h>
/* /*
* @implemented * @implemented
* copy _i64toa from wine cvs 2006 month 05 day 21
*/ */
char * char *
_i64toa(__int64 value, char *string, int radix) _i64toa(__int64 value, char *string, int radix)
{ {
char tmp[65]; ULONGLONG val;
char *tp = tmp; int negative;
__int64 i; char buffer[65];
unsigned __int64 v; char *pos;
__int64 sign; int digit;
char *sp;
if (radix > 36 || radix <= 1) if (value < 0 && radix == 10) {
{ negative = 1;
return 0; val = -value;
} } else {
negative = 0;
val = value;
} /* if */
sign = (radix == 10 && value < 0); pos = &buffer[64];
if (sign) *pos = '\0';
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;
}
sp = string; do {
if (sign) digit = val % radix;
*sp++ = '-'; val = val / radix;
while (tp > tmp) if (digit < 10) {
*sp++ = *--tp; *--pos = '0' + digit;
*sp = 0; } else {
return string; *--pos = 'a' + digit - 10;
} /* if */
} while (val != 0L);
if (negative) {
*--pos = '-';
} /* if */
memcpy(string, pos, &buffer[64] - pos + 1);
return string;
} }