msvcrt: Implemented _i64to[aw]_s.
authorEric Pouech <eric.pouech@orange.fr>
Mon, 15 Nov 2010 21:00:01 +0000 (22:00 +0100)
committerAlexandre Julliard <julliard@winehq.org>
Tue, 16 Nov 2010 11:01:43 +0000 (12:01 +0100)
dlls/msvcr100/msvcr100.spec
dlls/msvcr80/msvcr80.spec
dlls/msvcr90/msvcr90.spec
dlls/msvcrt/msvcrt.spec
dlls/msvcrt/string.c

index 4d26904..28243de 100644 (file)
 @ cdecl _hypot(double double) msvcrt._hypot
 @ cdecl _hypotf(float float) msvcrt._hypotf
 @ cdecl _i64toa(int64 ptr long) msvcrt._i64toa
-@ stub _i64toa_s
+@ cdecl _i64toa_s(int64 ptr long long) msvcrt._i64toa_s
 @ cdecl _i64tow(int64 ptr long) msvcrt._i64tow
-@ stub _i64tow_s
+@ cdecl _i64tow_s(int64 ptr long long) msvcrt._i64tow_s
 @ stub _initptd
 @ cdecl _initterm(ptr ptr) msvcrt._initterm
 @ cdecl _initterm_e(ptr ptr) msvcr90._initterm_e
index a65a89d..9206b93 100644 (file)
 @ cdecl _hypot(double double) msvcrt._hypot
 @ cdecl _hypotf(float float) msvcrt._hypotf
 @ cdecl _i64toa(int64 ptr long) msvcrt._i64toa
-@ stub _i64toa_s
+@ cdecl _i64toa_s(int64 ptr long long) msvcrt._i64toa_s
 @ cdecl _i64tow(int64 ptr long) msvcrt._i64tow
-@ stub _i64tow_s
+@ cdecl _i64tow_s(int64 ptr long long) msvcrt._i64tow_s
 @ stub _initptd
 @ cdecl _initterm(ptr ptr) msvcrt._initterm
 @ cdecl _initterm_e(ptr ptr) msvcr90._initterm_e
index 64332f5..c58637d 100644 (file)
 @ cdecl _hypot(double double) msvcrt._hypot
 @ cdecl _hypotf(float float) msvcrt._hypotf
 @ cdecl _i64toa(int64 ptr long) msvcrt._i64toa
-@ stub _i64toa_s
+@ cdecl _i64toa_s(int64 ptr long long) msvcrt._i64toa_s
 @ cdecl _i64tow(int64 ptr long) msvcrt._i64tow
-@ stub _i64tow_s
+@ cdecl _i64tow_s(int64 ptr long long) msvcrt._i64tow_s
 @ stub _initptd
 @ cdecl _initterm(ptr ptr) msvcrt._initterm
 @ cdecl _initterm_e(ptr ptr)
index 00ba5ea..c73a132 100644 (file)
 @ cdecl _hypot(double double)
 @ cdecl _hypotf(float float)
 @ cdecl _i64toa(int64 ptr long) ntdll._i64toa
-# stub _i64toa_s
+@ cdecl _i64toa_s(int64 ptr long long) _i64toa_s
 @ cdecl _i64tow(int64 ptr long) ntdll._i64tow
-# stub _i64tow_s
+@ cdecl _i64tow_s(int64 ptr long long) _i64tow_s
 @ cdecl _initterm(ptr ptr)
 # stub _initterm_e
 @ stub _inp #(long) -i386
index d807c14..11ad5a0 100644 (file)
@@ -972,6 +972,162 @@ int CDECL _ultoa_s(MSVCRT_ulong value, char *str, MSVCRT_size_t size, int radix)
     return 0;
 }
 
+/*********************************************************************
+ *  _i64toa_s (MSVCRT.@)
+ */
+int CDECL _i64toa_s(__int64 value, char *str, MSVCRT_size_t size, int radix)
+{
+    unsigned __int64 val;
+    unsigned int digit;
+    int is_negative;
+    char buffer[65], *pos;
+    size_t len;
+
+    if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
+        !MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
+    {
+        if (str && size)
+            str[0] = '\0';
+
+        *MSVCRT__errno() = MSVCRT_EINVAL;
+        return MSVCRT_EINVAL;
+    }
+
+    if (value < 0 && radix == 10)
+    {
+        is_negative = 1;
+        val = -value;
+    }
+    else
+    {
+        is_negative = 0;
+        val = value;
+    }
+
+    pos = buffer + 64;
+    *pos = '\0';
+
+    do
+    {
+        digit = val % radix;
+        val /= radix;
+
+        if (digit < 10)
+            *--pos = '0' + digit;
+        else
+            *--pos = 'a' + digit - 10;
+    }
+    while (val != 0);
+
+    if (is_negative)
+        *--pos = '-';
+
+    len = buffer + 65 - pos;
+    if (len > size)
+    {
+        size_t i;
+        char *p = str;
+
+        /* Copy the temporary buffer backwards up to the available number of
+         * characters. Don't copy the negative sign if present. */
+
+        if (is_negative)
+        {
+            p++;
+            size--;
+        }
+
+        for (pos = buffer + 63, i = 0; i < size; i++)
+            *p++ = *pos--;
+
+        str[0] = '\0';
+        MSVCRT_INVALID_PMT("str[size] is too small");
+        *MSVCRT__errno() = MSVCRT_ERANGE;
+        return MSVCRT_ERANGE;
+    }
+
+    memcpy(str, pos, len);
+    return 0;
+}
+
+/*********************************************************************
+ *  _i64tow_s (MSVCRT.@)
+ */
+int CDECL _i64tow_s(__int64 value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
+{
+    unsigned __int64 val;
+    unsigned int digit;
+    int is_negative;
+    MSVCRT_wchar_t buffer[65], *pos;
+    size_t len;
+
+    if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
+        !MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
+    {
+        if (str && size)
+            str[0] = '\0';
+
+        *MSVCRT__errno() = MSVCRT_EINVAL;
+        return MSVCRT_EINVAL;
+    }
+
+    if (value < 0 && radix == 10)
+    {
+        is_negative = 1;
+        val = -value;
+    }
+    else
+    {
+        is_negative = 0;
+        val = value;
+    }
+
+    pos = buffer + 64;
+    *pos = '\0';
+
+    do
+    {
+        digit = val % radix;
+        val /= radix;
+
+        if (digit < 10)
+            *--pos = '0' + digit;
+        else
+            *--pos = 'a' + digit - 10;
+    }
+    while (val != 0);
+
+    if (is_negative)
+        *--pos = '-';
+
+    len = buffer + 65 - pos;
+    if (len > size)
+    {
+        size_t i;
+        MSVCRT_wchar_t *p = str;
+
+        /* Copy the temporary buffer backwards up to the available number of
+         * characters. Don't copy the negative sign if present. */
+
+        if (is_negative)
+        {
+            p++;
+            size--;
+        }
+
+        for (pos = buffer + 63, i = 0; i < size; i++)
+            *p++ = *pos--;
+
+        MSVCRT_INVALID_PMT("str[size] is too small");
+        str[0] = '\0';
+        *MSVCRT__errno() = MSVCRT_ERANGE;
+        return MSVCRT_ERANGE;
+    }
+
+    memcpy(str, pos, len * sizeof(MSVCRT_wchar_t));
+    return 0;
+}
+
 #define I10_OUTPUT_MAX_PREC 21
 /* Internal structure used by $I10_OUTPUT */
 struct _I10_OUTPUT_DATA {