Alexandre Julliard : ntdll: Add _wcstoi64.

Alexandre Julliard julliard at winehq.org
Thu Jun 30 16:34:19 CDT 2022


Module: wine
Branch: master
Commit: ae1202cef0273fb8dc728d8f039062ea3aa2911f
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=ae1202cef0273fb8dc728d8f039062ea3aa2911f

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Jun 30 11:04:36 2022 +0200

ntdll: Add _wcstoi64.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/ntdll.spec |  1 +
 dlls/ntdll/wcstring.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 2a119c9a508..2ed68e1bc5d 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -1540,6 +1540,7 @@
 @ cdecl _wcslwr(wstr)
 @ cdecl _wcslwr_s(wstr long)
 @ cdecl _wcsnicmp(wstr wstr long)
+@ cdecl -ret64 _wcstoi64(wstr ptr long)
 @ cdecl _wcsupr(wstr)
 @ cdecl _wcsupr_s(wstr long)
 @ cdecl _wtoi(wstr)
diff --git a/dlls/ntdll/wcstring.c b/dlls/ntdll/wcstring.c
index 97d67ee38d0..06447248235 100644
--- a/dlls/ntdll/wcstring.c
+++ b/dlls/ntdll/wcstring.c
@@ -22,6 +22,7 @@
 
 #include <ctype.h>
 #include <errno.h>
+#include <limits.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
@@ -752,6 +753,53 @@ __msvcrt_ulong __cdecl wcstoul(LPCWSTR s, LPWSTR *end, INT base)
 }
 
 
+/*********************************************************************
+ *                  _wcstoi64  (NTDLL.@)
+ */
+__int64 __cdecl _wcstoi64( const wchar_t *s, wchar_t **end, int base )
+{
+    BOOL negative = FALSE, empty = TRUE;
+    __int64 ret = 0;
+
+    if (base < 0 || base == 1 || base > 36) return 0;
+    if (end) *end = (wchar_t *)s;
+    while (iswspace(*s)) s++;
+
+    if (*s == '-')
+    {
+        negative = TRUE;
+        s++;
+    }
+    else if (*s == '+') s++;
+
+    if ((base == 0 || base == 16) && !wctoint( *s ) && (s[1] == 'x' || s[1] == 'X'))
+    {
+        base = 16;
+        s += 2;
+    }
+    if (base == 0) base = wctoint( *s ) ? 10 : 8;
+
+    while (*s)
+    {
+        int v = wctoint( *s );
+        if (v < 0 || v >= base) break;
+        if (negative) v = -v;
+        s++;
+        empty = FALSE;
+
+        if (!negative && (ret > I64_MAX / base || ret * base > I64_MAX - v))
+            ret = I64_MAX;
+        else if (negative && (ret < I64_MIN / base || ret * base < I64_MIN - v))
+            ret = I64_MIN;
+        else
+            ret = ret * base + v;
+    }
+
+    if (end && !empty) *end = (wchar_t *)s;
+    return ret;
+}
+
+
 /*********************************************************************
  *      _ultow   (NTDLL.@)
  *




More information about the wine-cvs mailing list