083b3c
From e482b394efc371412ce659b731a9b1e1d73bdf0e Mon Sep 17 00:00:00 2001
083b3c
From: akallabeth <akallabeth@posteo.net>
083b3c
Date: Mon, 24 Oct 2022 10:42:56 +0200
083b3c
Subject: [PATCH] Added function _wcsncmp
083b3c
083b3c
* Compare WCHAR strings up to n characters
083b3c
083b3c
(cherry picked from commit 8178ed26a459356ece17414c6e871a7e0735a4ec)
083b3c
---
083b3c
 winpr/include/winpr/string.h |  2 ++
083b3c
 winpr/libwinpr/crt/string.c  | 15 ++++++++++++++-
083b3c
 2 files changed, 16 insertions(+), 1 deletion(-)
083b3c
083b3c
diff --git a/winpr/include/winpr/string.h b/winpr/include/winpr/string.h
083b3c
index 8ce83bc1d..3b907c444 100644
083b3c
--- a/winpr/include/winpr/string.h
083b3c
+++ b/winpr/include/winpr/string.h
083b3c
@@ -57,6 +57,7 @@ extern "C"
083b3c
 	WINPR_API int _strnicmp(const char* string1, const char* string2, size_t count);
083b3c
 
083b3c
 	WINPR_API int _wcscmp(const WCHAR* string1, const WCHAR* string2);
083b3c
+	WINPR_API int _wcsncmp(const WCHAR* string1, const WCHAR* string2, size_t count);
083b3c
 
083b3c
 	WINPR_API size_t _wcslen(const WCHAR* str);
083b3c
 	WINPR_API size_t _wcsnlen(const WCHAR* str, size_t maxNumberOfElements);
083b3c
@@ -70,6 +71,7 @@ extern "C"
083b3c
 #else
083b3c
 
083b3c
 #define _wcscmp wcscmp
083b3c
+#define _wcsncmp wcsncmp
083b3c
 #define _wcslen wcslen
083b3c
 #define _wcsnlen wcsnlen
083b3c
 #define _wcschr wcschr
083b3c
diff --git a/winpr/libwinpr/crt/string.c b/winpr/libwinpr/crt/string.c
083b3c
index 37fcb4b25..c25ffa279 100644
083b3c
--- a/winpr/libwinpr/crt/string.c
083b3c
+++ b/winpr/libwinpr/crt/string.c
083b3c
@@ -90,7 +90,20 @@ int _wcscmp(const WCHAR* string1, const WCHAR* string2)
083b3c
 
083b3c
 	Data_Read_UINT16(string1, value1);
083b3c
 	Data_Read_UINT16(string2, value2);
083b3c
-	return value1 - value2;
083b3c
+	return (int)value1 - value2;
083b3c
+}
083b3c
+
083b3c
+int _wcsncmp(const WCHAR* string1, const WCHAR* string2, size_t count)
083b3c
+{
083b3c
+	for (size_t x = 0; x < count; x++)
083b3c
+	{
083b3c
+		const WCHAR a = string1[x];
083b3c
+		const WCHAR b = string2[x];
083b3c
+
083b3c
+		if (a != b)
083b3c
+			return (int)a - b;
083b3c
+	}
083b3c
+	return 0;
083b3c
 }
083b3c
 
083b3c
 /* _wcslen -> wcslen */
083b3c
-- 
083b3c
2.37.1
083b3c