Skip to content

Commit 2899d91

Browse files
committed
[CRT] sync wtoi64.c with wine 1.9.16
svn path=/trunk/; revision=72641
1 parent d38c74f commit 2899d91

File tree

2 files changed

+174
-49
lines changed

2 files changed

+174
-49
lines changed

reactos/media/doc/README.WINE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ msvcrt -
300300
reactos/sdk/lib/crt/string/strxfrm.c # Synced to Wine-1.9.16
301301
reactos/sdk/lib/crt/string/wcs.c # Synced at 20080611
302302
reactos/sdk/lib/crt/string/wctype.c # Synced at WineStaging-1.9.16
303+
reactos/sdk/lib/crt/string/wtoi64.c # Synced at Wine-1.9.16
303304
reactos/sdk/lib/crt/wine/heap.c # Synced at 20080529
304305
reactos/sdk/lib/crt/wine/undname.c # Synced to WineStaging-1.9.16
305306
reactos/sdk/lib/crt/process/thread.c # Synced to WineStaging-1.7.55

reactos/sdk/lib/crt/string/wtoi64.c

Lines changed: 173 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,196 @@
1-
/*
2-
* COPYRIGHT: See COPYING in the top level directory
3-
* PROJECT: ReactOS system libraries
4-
* FILE: lib/sdk/crt/string/wtoi64.c
5-
* PURPOSE: Unknown
6-
* PROGRAMER: Unknown
7-
* UPDATE HISTORY:
8-
* 25/11/05: Added license header
1+
#include <precomp.h>
2+
#include <internal/wine/msvcrt.h>
3+
4+
/*********************************************************************
5+
* _wtoi64_l (MSVCRT.@)
96
*/
7+
__int64 CDECL _wtoi64_l(const wchar_t *str, _locale_t locale)
8+
{
9+
ULONGLONG RunningTotal = 0;
10+
BOOL bMinus = FALSE;
1011

11-
#include <precomp.h>
12+
while (isspaceW(*str)) {
13+
str++;
14+
} /* while */
15+
16+
if (*str == '+') {
17+
str++;
18+
} else if (*str == '-') {
19+
bMinus = TRUE;
20+
str++;
21+
} /* if */
22+
23+
while (*str >= '0' && *str <= '9') {
24+
RunningTotal = RunningTotal * 10 + *str - '0';
25+
str++;
26+
} /* while */
27+
28+
return bMinus ? -RunningTotal : RunningTotal;
29+
}
30+
31+
/*********************************************************************
32+
* _wtoi64 (MSVCRT.@)
33+
*/
34+
__int64 CDECL _wtoi64(const wchar_t *str)
35+
{
36+
return _wtoi64_l(str, NULL);
37+
}
1238

13-
/*
14-
* @implemented
39+
40+
/*********************************************************************
41+
* _wcstoi64_l (MSVCRT.@)
42+
*
43+
* FIXME: locale parameter is ignored
1544
*/
16-
__int64
17-
CDECL
18-
_wtoi64 (const wchar_t *nptr)
45+
__int64 CDECL _wcstoi64_l(const wchar_t *nptr,
46+
wchar_t **endptr, int base, _locale_t locale)
1947
{
20-
int c;
21-
__int64 value;
22-
int sign;
48+
BOOL negative = FALSE;
49+
__int64 ret = 0;
50+
51+
TRACE("(%s %p %d %p)\n", debugstr_w(nptr), endptr, base, locale);
52+
53+
if (!MSVCRT_CHECK_PMT(nptr != NULL)) return 0;
54+
if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
55+
if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
56+
57+
while(isspaceW(*nptr)) nptr++;
58+
59+
if(*nptr == '-') {
60+
negative = TRUE;
61+
nptr++;
62+
} else if(*nptr == '+')
63+
nptr++;
64+
65+
if((base==0 || base==16) && *nptr=='0' && tolowerW(*(nptr+1))=='x') {
66+
base = 16;
67+
nptr += 2;
68+
}
2369

24-
if (nptr == NULL)
25-
return 0;
70+
if(base == 0) {
71+
if(*nptr=='0')
72+
base = 8;
73+
else
74+
base = 10;
75+
}
2676

27-
while (iswctype((int)*nptr, _SPACE))
28-
++nptr;
77+
while(*nptr) {
78+
wchar_t cur = tolowerW(*nptr);
79+
int v;
2980

30-
c = (int)*nptr++;
31-
sign = c;
32-
if (c == L'-' || c == L'+')
33-
c = (int)*nptr++;
81+
if(cur>='0' && cur<='9') {
82+
if(cur >= '0'+base)
83+
break;
84+
v = cur-'0';
85+
} else {
86+
if(cur<'a' || cur>='a'+base-10)
87+
break;
88+
v = cur-'a'+10;
89+
}
3490

35-
value = 0;
91+
if(negative)
92+
v = -v;
3693

37-
while (iswctype(c, _DIGIT))
38-
{
39-
value = 10 * value + (c - L'0');
40-
c = (int)*nptr++;
41-
}
94+
nptr++;
4295

43-
if (sign == L'-')
44-
return -value;
45-
else
46-
return value;
96+
if(!negative && (ret>_I64_MAX/base || ret*base>_I64_MAX-v)) {
97+
ret = _I64_MAX;
98+
*_errno() = ERANGE;
99+
} else if(negative && (ret<_I64_MIN/base || ret*base<_I64_MIN-v)) {
100+
ret = _I64_MIN;
101+
*_errno() = ERANGE;
102+
} else
103+
ret = ret*base + v;
104+
}
105+
106+
if(endptr)
107+
*endptr = (wchar_t*)nptr;
108+
109+
return ret;
47110
}
48111

112+
/*********************************************************************
113+
* _wcstoi64 (MSVCRT.@)
114+
*/
115+
__int64 CDECL _wcstoi64(const wchar_t *nptr,
116+
wchar_t **endptr, int base)
117+
{
118+
return _wcstoi64_l(nptr, endptr, base, NULL);
119+
}
49120

50-
/*
51-
* @unimplemented
121+
/*********************************************************************
122+
* _wcstoui64_l (MSVCRT.@)
123+
*
124+
* FIXME: locale parameter is ignored
52125
*/
53-
__int64
54-
CDECL
55-
_wcstoi64 (const wchar_t *nptr, wchar_t **endptr, int base)
126+
unsigned __int64 CDECL _wcstoui64_l(const wchar_t *nptr,
127+
wchar_t **endptr, int base, _locale_t locale)
56128
{
57-
TRACE("_wcstoi64 is UNIMPLEMENTED\n");
58-
return 0;
129+
BOOL negative = FALSE;
130+
unsigned __int64 ret = 0;
131+
132+
TRACE("(%s %p %d %p)\n", debugstr_w(nptr), endptr, base, locale);
133+
134+
if (!MSVCRT_CHECK_PMT(nptr != NULL)) return 0;
135+
if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
136+
if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
137+
138+
while(isspaceW(*nptr)) nptr++;
139+
140+
if(*nptr == '-') {
141+
negative = TRUE;
142+
nptr++;
143+
} else if(*nptr == '+')
144+
nptr++;
145+
146+
if((base==0 || base==16) && *nptr=='0' && tolowerW(*(nptr+1))=='x') {
147+
base = 16;
148+
nptr += 2;
149+
}
150+
151+
if(base == 0) {
152+
if(*nptr=='0')
153+
base = 8;
154+
else
155+
base = 10;
156+
}
157+
158+
while(*nptr) {
159+
wchar_t cur = tolowerW(*nptr);
160+
int v;
161+
162+
if(cur>='0' && cur<='9') {
163+
if(cur >= '0'+base)
164+
break;
165+
v = *nptr-'0';
166+
} else {
167+
if(cur<'a' || cur>='a'+base-10)
168+
break;
169+
v = cur-'a'+10;
170+
}
171+
172+
nptr++;
173+
174+
if(ret>_UI64_MAX/base || ret*base>_UI64_MAX-v) {
175+
ret = _UI64_MAX;
176+
*_errno() = ERANGE;
177+
} else
178+
ret = ret*base + v;
179+
}
180+
181+
if(endptr)
182+
*endptr = (wchar_t*)nptr;
183+
184+
return negative ? -ret : ret;
59185
}
60186

61-
/*
62-
* @unimplemented
187+
/*********************************************************************
188+
* _wcstoui64 (MSVCRT.@)
63189
*/
64-
unsigned __int64
65-
CDECL
66-
_wcstoui64 (const wchar_t *nptr, wchar_t **endptr, int base)
190+
unsigned __int64 CDECL _wcstoui64(const wchar_t *nptr,
191+
wchar_t **endptr, int base)
67192
{
68-
TRACE("_wcstoui64 is UNIMPLEMENTED\n");
69-
return 0;
193+
return _wcstoui64_l(nptr, endptr, base, NULL);
70194
}
71195

72196

0 commit comments

Comments
 (0)