Alexandre Julliard : ntdll: Add strncat_s and wcsncat_s.

Alexandre Julliard julliard at winehq.org
Wed Jun 29 16:25:53 CDT 2022


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed Jun 29 11:49:55 2022 +0200

ntdll: Add strncat_s and wcsncat_s.

Implementation copied from msvcrt.

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

---

 dlls/ntdll/ntdll.spec |  2 ++
 dlls/ntdll/string.c   | 41 +++++++++++++++++++++++++++++++++++++++++
 dlls/ntdll/wcstring.c | 41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+)

diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 95b2e652b3d..e02c4278deb 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -1595,6 +1595,7 @@
 @ cdecl strcspn(str str)
 @ cdecl strlen(str)
 @ cdecl strncat(str str long)
+@ cdecl strncat_s(str long str long)
 @ cdecl strncmp(str str long)
 @ cdecl strncpy(ptr str long)
 @ cdecl strncpy_s(ptr long str long)
@@ -1626,6 +1627,7 @@
 @ cdecl wcscspn(wstr wstr)
 @ cdecl wcslen(wstr)
 @ cdecl wcsncat(wstr wstr long)
+@ cdecl wcsncat_s(wstr long wstr long)
 @ cdecl wcsncmp(wstr wstr long)
 @ cdecl wcsncpy(ptr wstr long)
 @ cdecl wcsncpy_s(ptr long wstr long)
diff --git a/dlls/ntdll/string.c b/dlls/ntdll/string.c
index 212cd30e2f1..6c4ac47803a 100644
--- a/dlls/ntdll/string.c
+++ b/dlls/ntdll/string.c
@@ -332,6 +332,47 @@ char * __cdecl strncat( char *dst, const char *src, size_t len )
 }
 
 
+/*********************************************************************
+ *                  strncat_s   (NTDLL.@)
+ */
+errno_t __cdecl strncat_s( char *dst, size_t len, const char *src, size_t count )
+{
+    size_t i, j;
+
+    if (!dst || !len) return EINVAL;
+    if (!count) return 0;
+    if (!src)
+    {
+        *dst = 0;
+        return EINVAL;
+    }
+
+    for (i = 0; i < len; i++) if (!dst[i]) break;
+
+    if (i == len)
+    {
+        *dst = 0;
+        return EINVAL;
+    }
+
+    for (j = 0; (j + i) < len; j++)
+    {
+        if (count == _TRUNCATE && j + i == len - 1)
+        {
+            dst[j + i] = 0;
+            return STRUNCATE;
+        }
+        if (j == count || !(dst[j + i] = src[j]))
+        {
+            dst[j + i] = 0;
+            return 0;
+        }
+    }
+    *dst = 0;
+    return ERANGE;
+}
+
+
 /*********************************************************************
  *                  strncmp   (NTDLL.@)
  */
diff --git a/dlls/ntdll/wcstring.c b/dlls/ntdll/wcstring.c
index cb45986207d..e481c89ca71 100644
--- a/dlls/ntdll/wcstring.c
+++ b/dlls/ntdll/wcstring.c
@@ -268,6 +268,47 @@ LPWSTR __cdecl wcsncat( LPWSTR s1, LPCWSTR s2, size_t n )
 }
 
 
+/*********************************************************************
+ *           wcsncat_s    (NTDLL.@)
+ */
+errno_t __cdecl wcsncat_s( wchar_t *dst, size_t len, const wchar_t *src, size_t count )
+{
+    size_t i, j;
+
+    if (!dst || !len) return EINVAL;
+    if (!count) return 0;
+    if (!src)
+    {
+        *dst = 0;
+        return EINVAL;
+    }
+
+    for (i = 0; i < len; i++) if (!dst[i]) break;
+
+    if (i == len)
+    {
+        *dst = 0;
+        return EINVAL;
+    }
+
+    for (j = 0; (j + i) < len; j++)
+    {
+        if (count == _TRUNCATE && j + i == len - 1)
+        {
+            dst[j + i] = 0;
+            return STRUNCATE;
+        }
+        if (j == count || !(dst[j + i] = src[j]))
+        {
+            dst[j + i] = 0;
+            return 0;
+        }
+    }
+    *dst = 0;
+    return ERANGE;
+}
+
+
 /*********************************************************************
  *           wcsncmp    (NTDLL.@)
  */




More information about the wine-cvs mailing list