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