mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 09:25:10 +00:00
[CRT]
import strtoi64 from wine 1.3.10 svn path=/trunk/; revision=50159
This commit is contained in:
parent
cd7f6a4a36
commit
fdea91b64c
1 changed files with 56 additions and 2 deletions
|
@ -4,8 +4,62 @@
|
||||||
__int64
|
__int64
|
||||||
_strtoi64(const char *nptr, char **endptr, int base)
|
_strtoi64(const char *nptr, char **endptr, int base)
|
||||||
{
|
{
|
||||||
TRACE("_strtoi64 is UNIMPLEMENTED\n");
|
BOOL negative = FALSE;
|
||||||
return 0;
|
__int64 ret = 0;
|
||||||
|
|
||||||
|
while(isspace(*nptr)) nptr++;
|
||||||
|
|
||||||
|
if(*nptr == '-') {
|
||||||
|
negative = TRUE;
|
||||||
|
nptr++;
|
||||||
|
} else if(*nptr == '+')
|
||||||
|
nptr++;
|
||||||
|
|
||||||
|
if((base==0 || base==16) && *nptr=='0' && tolower(*(nptr+1))=='x') {
|
||||||
|
base = 16;
|
||||||
|
nptr += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(base == 0) {
|
||||||
|
if(*nptr=='0')
|
||||||
|
base = 8;
|
||||||
|
else
|
||||||
|
base = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(*nptr) {
|
||||||
|
char cur = tolower(*nptr);
|
||||||
|
int v;
|
||||||
|
|
||||||
|
if(isdigit(cur)) {
|
||||||
|
if(cur >= '0'+base)
|
||||||
|
break;
|
||||||
|
v = cur-'0';
|
||||||
|
} else {
|
||||||
|
if(cur<'a' || cur>='a'+base-10)
|
||||||
|
break;
|
||||||
|
v = cur-'a'+10;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(negative)
|
||||||
|
v = -v;
|
||||||
|
|
||||||
|
nptr++;
|
||||||
|
|
||||||
|
if(!negative && (ret>_I64_MAX/base || ret*base>_I64_MAX-v)) {
|
||||||
|
ret = _I64_MAX;
|
||||||
|
*_errno() = ERANGE;
|
||||||
|
} else if(negative && (ret<_I64_MIN/base || ret*base<_I64_MIN-v)) {
|
||||||
|
ret = _I64_MIN;
|
||||||
|
*_errno() = ERANGE;
|
||||||
|
} else
|
||||||
|
ret = ret*base + v;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(endptr)
|
||||||
|
*endptr = (char*)nptr;
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue