Blame SOURCES/Added-function-_wcsncmp.patch

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