Module: wine Branch: master Commit: 41f488a32d17b47a88606d538f6ab10fed96bad6 URL: https://source.winehq.org/git/wine.git/?a=commit;h=41f488a32d17b47a88606d538...
Author: Alexandre Julliard julliard@winehq.org Date: Wed Jun 29 11:48:47 2022 +0200
ntdll: Add strcpy_s and wcscpy_s.
Implementation copied from msvcrt.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/ntdll/ntdll.spec | 2 ++ dlls/ntdll/string.c | 21 +++++++++++++++++++++ dlls/ntdll/wcstring.c | 21 +++++++++++++++++++++ 3 files changed, 44 insertions(+)
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index fa1941ec811..93cb322f06d 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -1590,6 +1590,7 @@ @ cdecl strchr(str long) @ cdecl strcmp(str str) @ cdecl strcpy(ptr str) +@ cdecl strcpy_s(ptr long str) @ cdecl strcspn(str str) @ cdecl strlen(str) @ cdecl strncat(str str long) @@ -1618,6 +1619,7 @@ @ cdecl wcschr(wstr long) @ cdecl wcscmp(wstr wstr) @ cdecl wcscpy(ptr wstr) +@ cdecl wcscpy_s(ptr long wstr) @ cdecl wcscspn(wstr wstr) @ cdecl wcslen(wstr) @ cdecl wcsncat(wstr wstr long) diff --git a/dlls/ntdll/string.c b/dlls/ntdll/string.c index 9c46b02aac4..6308ecfe049 100644 --- a/dlls/ntdll/string.c +++ b/dlls/ntdll/string.c @@ -21,6 +21,7 @@ */
#include <limits.h> +#include <errno.h> #include <stdarg.h> #include <stdlib.h> #include <stdio.h> @@ -256,6 +257,26 @@ char * __cdecl strcpy( char *dst, const char *src ) }
+/********************************************************************* + * strcpy_s (NTDLL.@) + */ +errno_t __cdecl strcpy_s( char *dst, size_t len, const char *src ) +{ + size_t i; + + if (!dst || !len) return EINVAL; + if (!src) + { + *dst = 0; + return EINVAL; + } + + for (i = 0; i < len; i++) if (!(dst[i] = src[i])) return 0; + *dst = 0; + return ERANGE; +} + + /********************************************************************* * strcspn (NTDLL.@) */ diff --git a/dlls/ntdll/wcstring.c b/dlls/ntdll/wcstring.c index eef3197c4fe..b6afdb1d72e 100644 --- a/dlls/ntdll/wcstring.c +++ b/dlls/ntdll/wcstring.c @@ -21,6 +21,7 @@ */
#include <ctype.h> +#include <errno.h> #include <stdlib.h> #include <string.h> #include <stdarg.h> @@ -162,6 +163,26 @@ LPWSTR __cdecl wcscpy( LPWSTR dst, LPCWSTR src ) }
+/********************************************************************* + * wcscpy_s (NTDLL.@) + */ +errno_t __cdecl wcscpy_s( wchar_t *dst, size_t len, const wchar_t *src ) +{ + size_t i; + + if (!dst || !len) return EINVAL; + if (!src) + { + *dst = 0; + return EINVAL; + } + + for (i = 0; i < len; i++) if (!(dst[i] = src[i])) return 0; + *dst = 0; + return ERANGE; +} + + /*********************************************************************** * wcslen (NTDLL.@) */