Alexandre Julliard : ntdll: Add strncpy_s and wcsncpy_s.
Alexandre Julliard
julliard at winehq.org
Wed Jun 29 16:25:53 CDT 2022
Module: wine
Branch: master
Commit: 94e960c861c013771d72022ef994d38e937cef58
URL: https://source.winehq.org/git/wine.git/?a=commit;h=94e960c861c013771d72022ef994d38e937cef58
Author: Alexandre Julliard <julliard at winehq.org>
Date: Wed Jun 29 11:49:38 2022 +0200
ntdll: Add strncpy_s and wcsncpy_s.
Implementation copied from msvcrt.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ntdll/ntdll.spec | 2 ++
dlls/ntdll/string.c | 42 ++++++++++++++++++++++++++++++++++++++++++
dlls/ntdll/wcstring.c | 42 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 86 insertions(+)
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 1e94d23c7df..95b2e652b3d 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -1597,6 +1597,7 @@
@ cdecl strncat(str str long)
@ cdecl strncmp(str str long)
@ cdecl strncpy(ptr str long)
+@ cdecl strncpy_s(ptr long str long)
@ cdecl strnlen(ptr long)
@ cdecl strpbrk(str str)
@ cdecl strrchr(str long)
@@ -1627,6 +1628,7 @@
@ cdecl wcsncat(wstr wstr long)
@ cdecl wcsncmp(wstr wstr long)
@ cdecl wcsncpy(ptr wstr long)
+@ cdecl wcsncpy_s(ptr long wstr long)
@ cdecl wcsnlen(ptr long)
@ cdecl wcspbrk(wstr wstr)
@ cdecl wcsrchr(wstr long)
diff --git a/dlls/ntdll/string.c b/dlls/ntdll/string.c
index 8a37cd6d8d4..212cd30e2f1 100644
--- a/dlls/ntdll/string.c
+++ b/dlls/ntdll/string.c
@@ -356,6 +356,48 @@ char * __cdecl strncpy( char *dst, const char *src, size_t len )
}
+/*********************************************************************
+ * strncpy_s (NTDLL.@)
+ */
+errno_t __cdecl strncpy_s( char *dst, size_t len, const char *src, size_t count )
+{
+ size_t i, end;
+
+ if (!count)
+ {
+ if (dst && len) *dst = 0;
+ return 0;
+ }
+ if (!dst || !len) return EINVAL;
+ if (!src)
+ {
+ *dst = 0;
+ return EINVAL;
+ }
+
+ if (count != _TRUNCATE && count < len)
+ end = count;
+ else
+ end = len - 1;
+
+ for (i = 0; i < end; i++)
+ if (!(dst[i] = src[i])) return 0;
+
+ if (count == _TRUNCATE)
+ {
+ dst[i] = 0;
+ return STRUNCATE;
+ }
+ if (end == count)
+ {
+ dst[i] = 0;
+ return 0;
+ }
+ dst[0] = 0;
+ return ERANGE;
+}
+
+
/*********************************************************************
* strnlen (NTDLL.@)
*/
diff --git a/dlls/ntdll/wcstring.c b/dlls/ntdll/wcstring.c
index d5e50981153..cb45986207d 100644
--- a/dlls/ntdll/wcstring.c
+++ b/dlls/ntdll/wcstring.c
@@ -292,6 +292,48 @@ LPWSTR __cdecl wcsncpy( LPWSTR s1, LPCWSTR s2, size_t n )
}
+/*********************************************************************
+ * wcsncpy_s (NTDLL.@)
+ */
+errno_t __cdecl wcsncpy_s( wchar_t *dst, size_t len, const wchar_t *src, size_t count )
+{
+ size_t i, end;
+
+ if (!count)
+ {
+ if (dst && len) *dst = 0;
+ return 0;
+ }
+ if (!dst || !len) return EINVAL;
+ if (!src)
+ {
+ *dst = 0;
+ return EINVAL;
+ }
+
+ if (count != _TRUNCATE && count < len)
+ end = count;
+ else
+ end = len - 1;
+
+ for (i = 0; i < end; i++)
+ if (!(dst[i] = src[i])) return 0;
+
+ if (count == _TRUNCATE)
+ {
+ dst[i] = 0;
+ return STRUNCATE;
+ }
+ if (end == count)
+ {
+ dst[i] = 0;
+ return 0;
+ }
+ dst[0] = 0;
+ return ERANGE;
+}
+
+
/*********************************************************************
* wcsnlen (NTDLL.@)
*/
More information about the wine-cvs
mailing list