mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 00:05:44 +00:00
[CRT] sync wtoi64.c with wine 1.9.16
svn path=/trunk/; revision=72641
This commit is contained in:
parent
d38c74fa76
commit
2899d91c28
2 changed files with 176 additions and 51 deletions
|
@ -300,6 +300,7 @@ msvcrt -
|
||||||
reactos/sdk/lib/crt/string/strxfrm.c # Synced to Wine-1.9.16
|
reactos/sdk/lib/crt/string/strxfrm.c # Synced to Wine-1.9.16
|
||||||
reactos/sdk/lib/crt/string/wcs.c # Synced at 20080611
|
reactos/sdk/lib/crt/string/wcs.c # Synced at 20080611
|
||||||
reactos/sdk/lib/crt/string/wctype.c # Synced at WineStaging-1.9.16
|
reactos/sdk/lib/crt/string/wctype.c # Synced at WineStaging-1.9.16
|
||||||
|
reactos/sdk/lib/crt/string/wtoi64.c # Synced at Wine-1.9.16
|
||||||
reactos/sdk/lib/crt/wine/heap.c # Synced at 20080529
|
reactos/sdk/lib/crt/wine/heap.c # Synced at 20080529
|
||||||
reactos/sdk/lib/crt/wine/undname.c # Synced to WineStaging-1.9.16
|
reactos/sdk/lib/crt/wine/undname.c # Synced to WineStaging-1.9.16
|
||||||
reactos/sdk/lib/crt/process/thread.c # Synced to WineStaging-1.7.55
|
reactos/sdk/lib/crt/process/thread.c # Synced to WineStaging-1.7.55
|
||||||
|
|
|
@ -1,72 +1,196 @@
|
||||||
/*
|
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
|
||||||
* PROJECT: ReactOS system libraries
|
|
||||||
* FILE: lib/sdk/crt/string/wtoi64.c
|
|
||||||
* PURPOSE: Unknown
|
|
||||||
* PROGRAMER: Unknown
|
|
||||||
* UPDATE HISTORY:
|
|
||||||
* 25/11/05: Added license header
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <precomp.h>
|
#include <precomp.h>
|
||||||
|
#include <internal/wine/msvcrt.h>
|
||||||
|
|
||||||
/*
|
/*********************************************************************
|
||||||
* @implemented
|
* _wtoi64_l (MSVCRT.@)
|
||||||
*/
|
*/
|
||||||
__int64
|
__int64 CDECL _wtoi64_l(const wchar_t *str, _locale_t locale)
|
||||||
CDECL
|
|
||||||
_wtoi64 (const wchar_t *nptr)
|
|
||||||
{
|
{
|
||||||
int c;
|
ULONGLONG RunningTotal = 0;
|
||||||
__int64 value;
|
BOOL bMinus = FALSE;
|
||||||
int sign;
|
|
||||||
|
|
||||||
if (nptr == NULL)
|
while (isspaceW(*str)) {
|
||||||
return 0;
|
str++;
|
||||||
|
} /* while */
|
||||||
|
|
||||||
while (iswctype((int)*nptr, _SPACE))
|
if (*str == '+') {
|
||||||
++nptr;
|
str++;
|
||||||
|
} else if (*str == '-') {
|
||||||
|
bMinus = TRUE;
|
||||||
|
str++;
|
||||||
|
} /* if */
|
||||||
|
|
||||||
c = (int)*nptr++;
|
while (*str >= '0' && *str <= '9') {
|
||||||
sign = c;
|
RunningTotal = RunningTotal * 10 + *str - '0';
|
||||||
if (c == L'-' || c == L'+')
|
str++;
|
||||||
c = (int)*nptr++;
|
} /* while */
|
||||||
|
|
||||||
value = 0;
|
return bMinus ? -RunningTotal : RunningTotal;
|
||||||
|
}
|
||||||
|
|
||||||
while (iswctype(c, _DIGIT))
|
/*********************************************************************
|
||||||
{
|
* _wtoi64 (MSVCRT.@)
|
||||||
value = 10 * value + (c - L'0');
|
*/
|
||||||
c = (int)*nptr++;
|
__int64 CDECL _wtoi64(const wchar_t *str)
|
||||||
}
|
{
|
||||||
|
return _wtoi64_l(str, NULL);
|
||||||
if (sign == L'-')
|
|
||||||
return -value;
|
|
||||||
else
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*********************************************************************
|
||||||
* @unimplemented
|
* _wcstoi64_l (MSVCRT.@)
|
||||||
|
*
|
||||||
|
* FIXME: locale parameter is ignored
|
||||||
*/
|
*/
|
||||||
__int64
|
__int64 CDECL _wcstoi64_l(const wchar_t *nptr,
|
||||||
CDECL
|
wchar_t **endptr, int base, _locale_t locale)
|
||||||
_wcstoi64 (const wchar_t *nptr, wchar_t **endptr, int base)
|
|
||||||
{
|
{
|
||||||
TRACE("_wcstoi64 is UNIMPLEMENTED\n");
|
BOOL negative = FALSE;
|
||||||
return 0;
|
__int64 ret = 0;
|
||||||
|
|
||||||
|
TRACE("(%s %p %d %p)\n", debugstr_w(nptr), endptr, base, locale);
|
||||||
|
|
||||||
|
if (!MSVCRT_CHECK_PMT(nptr != NULL)) return 0;
|
||||||
|
if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
|
||||||
|
if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
|
||||||
|
|
||||||
|
while(isspaceW(*nptr)) nptr++;
|
||||||
|
|
||||||
|
if(*nptr == '-') {
|
||||||
|
negative = TRUE;
|
||||||
|
nptr++;
|
||||||
|
} else if(*nptr == '+')
|
||||||
|
nptr++;
|
||||||
|
|
||||||
|
if((base==0 || base==16) && *nptr=='0' && tolowerW(*(nptr+1))=='x') {
|
||||||
|
base = 16;
|
||||||
|
nptr += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(base == 0) {
|
||||||
|
if(*nptr=='0')
|
||||||
|
base = 8;
|
||||||
|
else
|
||||||
|
base = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(*nptr) {
|
||||||
|
wchar_t cur = tolowerW(*nptr);
|
||||||
|
int v;
|
||||||
|
|
||||||
|
if(cur>='0' && cur<='9') {
|
||||||
|
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 = (wchar_t*)nptr;
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*********************************************************************
|
||||||
* @unimplemented
|
* _wcstoi64 (MSVCRT.@)
|
||||||
*/
|
*/
|
||||||
unsigned __int64
|
__int64 CDECL _wcstoi64(const wchar_t *nptr,
|
||||||
CDECL
|
wchar_t **endptr, int base)
|
||||||
_wcstoui64 (const wchar_t *nptr, wchar_t **endptr, int base)
|
|
||||||
{
|
{
|
||||||
TRACE("_wcstoui64 is UNIMPLEMENTED\n");
|
return _wcstoi64_l(nptr, endptr, base, NULL);
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* _wcstoui64_l (MSVCRT.@)
|
||||||
|
*
|
||||||
|
* FIXME: locale parameter is ignored
|
||||||
|
*/
|
||||||
|
unsigned __int64 CDECL _wcstoui64_l(const wchar_t *nptr,
|
||||||
|
wchar_t **endptr, int base, _locale_t locale)
|
||||||
|
{
|
||||||
|
BOOL negative = FALSE;
|
||||||
|
unsigned __int64 ret = 0;
|
||||||
|
|
||||||
|
TRACE("(%s %p %d %p)\n", debugstr_w(nptr), endptr, base, locale);
|
||||||
|
|
||||||
|
if (!MSVCRT_CHECK_PMT(nptr != NULL)) return 0;
|
||||||
|
if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
|
||||||
|
if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
|
||||||
|
|
||||||
|
while(isspaceW(*nptr)) nptr++;
|
||||||
|
|
||||||
|
if(*nptr == '-') {
|
||||||
|
negative = TRUE;
|
||||||
|
nptr++;
|
||||||
|
} else if(*nptr == '+')
|
||||||
|
nptr++;
|
||||||
|
|
||||||
|
if((base==0 || base==16) && *nptr=='0' && tolowerW(*(nptr+1))=='x') {
|
||||||
|
base = 16;
|
||||||
|
nptr += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(base == 0) {
|
||||||
|
if(*nptr=='0')
|
||||||
|
base = 8;
|
||||||
|
else
|
||||||
|
base = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(*nptr) {
|
||||||
|
wchar_t cur = tolowerW(*nptr);
|
||||||
|
int v;
|
||||||
|
|
||||||
|
if(cur>='0' && cur<='9') {
|
||||||
|
if(cur >= '0'+base)
|
||||||
|
break;
|
||||||
|
v = *nptr-'0';
|
||||||
|
} else {
|
||||||
|
if(cur<'a' || cur>='a'+base-10)
|
||||||
|
break;
|
||||||
|
v = cur-'a'+10;
|
||||||
|
}
|
||||||
|
|
||||||
|
nptr++;
|
||||||
|
|
||||||
|
if(ret>_UI64_MAX/base || ret*base>_UI64_MAX-v) {
|
||||||
|
ret = _UI64_MAX;
|
||||||
|
*_errno() = ERANGE;
|
||||||
|
} else
|
||||||
|
ret = ret*base + v;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(endptr)
|
||||||
|
*endptr = (wchar_t*)nptr;
|
||||||
|
|
||||||
|
return negative ? -ret : ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* _wcstoui64 (MSVCRT.@)
|
||||||
|
*/
|
||||||
|
unsigned __int64 CDECL _wcstoui64(const wchar_t *nptr,
|
||||||
|
wchar_t **endptr, int base)
|
||||||
|
{
|
||||||
|
return _wcstoui64_l(nptr, endptr, base, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue