Alexandre Julliard : ntdll: Add _i64tow_s.

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


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

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

ntdll: Add _i64tow_s.

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

---

 dlls/ntdll/ntdll.spec |  3 +++
 dlls/ntdll/wcstring.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)

diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 9666fcc7f36..51041c4144b 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -1504,12 +1504,15 @@
 @ cdecl -arch=i386 -ret64 _ftol()
 @ cdecl _i64toa(int64 ptr long)
 @ cdecl _i64tow(int64 ptr long)
+@ cdecl _i64tow_s(int64 ptr long long)
 @ cdecl _itoa(long ptr long)
 @ cdecl _itow(long ptr long)
+@ cdecl _itow_s(long ptr long long)
 @ cdecl _lfind(ptr ptr ptr long ptr)
 @ stdcall -arch=x86_64,arm64 _local_unwind(ptr ptr)
 @ cdecl _ltoa(long ptr long)
 @ cdecl _ltow(long ptr long)
+@ cdecl _ltow_s(long ptr long long)
 @ cdecl _memccpy(ptr ptr long long)
 @ cdecl _memicmp(str str long)
 @ varargs _snprintf(ptr long str) NTDLL__snprintf
diff --git a/dlls/ntdll/wcstring.c b/dlls/ntdll/wcstring.c
index 8d53388f4c4..a0d7042f30c 100644
--- a/dlls/ntdll/wcstring.c
+++ b/dlls/ntdll/wcstring.c
@@ -1127,6 +1127,80 @@ errno_t __cdecl _ultow_s( __msvcrt_ulong value, wchar_t *str, size_t size, int r
 }
 
 
+/*********************************************************************
+ *      _i64tow_s  (NTDLL.@)
+ */
+errno_t __cdecl _i64tow_s( __int64 value, wchar_t *str, size_t size, int radix )
+{
+    unsigned __int64 val;
+    BOOL is_negative;
+    wchar_t buffer[65], *pos;
+
+    if (!str || !size) return EINVAL;
+    if (radix < 2 || radix > 36)
+    {
+        str[0] = 0;
+        return EINVAL;
+    }
+
+    if (value < 0 && radix == 10)
+    {
+        is_negative = TRUE;
+        val = -value;
+    }
+    else
+    {
+        is_negative = FALSE;
+        val = value;
+    }
+
+    pos = buffer + 64;
+    *pos = 0;
+
+    do
+    {
+        unsigned int digit = val % radix;
+        val /= radix;
+
+        if (digit < 10)
+            *--pos = '0' + digit;
+        else
+            *--pos = 'a' + digit - 10;
+    }
+    while (val != 0);
+
+    if (is_negative) *--pos = '-';
+
+    if (buffer - pos + 65 > size)
+    {
+        str[0] = 0;
+        return ERANGE;
+    }
+    memcpy( str, pos, (buffer - pos + 65) * sizeof(wchar_t) );
+    return 0;
+}
+
+
+/*********************************************************************
+ *      _ltow_s  (NTDLL.@)
+ */
+errno_t __cdecl _ltow_s( __msvcrt_long value, wchar_t *str, size_t size, int radix )
+{
+    if (value < 0 && radix == 10) return _i64tow_s( value, str, size, radix );
+    return _ui64tow_s( (__msvcrt_ulong)value, str, size, radix );
+}
+
+
+/*********************************************************************
+ *      _itow_s  (NTDLL.@)
+ */
+errno_t __cdecl _itow_s( int value, wchar_t *str, size_t size, int radix )
+{
+    if (value < 0 && radix == 10) return _i64tow_s( value, str, size, radix );
+    return _ui64tow_s( (unsigned int)value, str, size, radix );
+}
+
+
 /*********************************************************************
  *      _wtol    (NTDLL.@)
  *




More information about the wine-cvs mailing list