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