Alexandre Julliard : ntdll: Add _i64toa_s.

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


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

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

ntdll: Add _i64toa_s.

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

---

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

diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index d592b7adbb4..a3832042704 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -1503,14 +1503,17 @@
 @ stub _fltused
 @ cdecl -arch=i386 -ret64 _ftol()
 @ cdecl _i64toa(int64 ptr long)
+@ cdecl _i64toa_s(int64 ptr long long)
 @ cdecl _i64tow(int64 ptr long)
 @ cdecl _i64tow_s(int64 ptr long long)
 @ cdecl _itoa(long ptr long)
+@ cdecl _itoa_s(long ptr long 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 _ltoa_s(long ptr long long)
 @ cdecl _ltow(long ptr long)
 @ cdecl _ltow_s(long ptr long long)
 @ cdecl _memccpy(ptr ptr long long)
diff --git a/dlls/ntdll/string.c b/dlls/ntdll/string.c
index 797152a81e1..5a971a4a0b2 100644
--- a/dlls/ntdll/string.c
+++ b/dlls/ntdll/string.c
@@ -1258,6 +1258,80 @@ errno_t __cdecl _ultoa_s( __msvcrt_ulong value, char *str, size_t size, int radi
 }
 
 
+/*********************************************************************
+ *      _i64toa_s  (NTDLL.@)
+ */
+errno_t __cdecl _i64toa_s( __int64 value, char *str, size_t size, int radix )
+{
+    unsigned __int64 val;
+    BOOL is_negative;
+    char 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 );
+    return 0;
+}
+
+
+/*********************************************************************
+ *      _ltoa_s  (NTDLL.@)
+ */
+errno_t __cdecl _ltoa_s( __msvcrt_long value, char *str, size_t size, int radix )
+{
+    if (value < 0 && radix == 10) return _i64toa_s( value, str, size, radix );
+    return _ui64toa_s( (__msvcrt_ulong)value, str, size, radix );
+}
+
+
+/*********************************************************************
+ *      _itoa_s  (NTDLL.@)
+ */
+errno_t __cdecl _itoa_s( int value, char *str, size_t size, int radix )
+{
+    if (value < 0 && radix == 10) return _i64toa_s( value, str, size, radix );
+    return _ui64toa_s( (unsigned int)value, str, size, radix );
+}
+
+
 /*********************************************************************
  *      _atoi64   (NTDLL.@)
  *




More information about the wine-cvs mailing list