mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 03:15:43 +00:00
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:
parent
c94db29865
commit
f340ab0a45
2 changed files with 63 additions and 65 deletions
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -1,46 +1,47 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
|
||||
/*
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue