Blob Blame History Raw
From ddc6dacd06b41ed5001b1c884b5d5c9e0a70e275 Mon Sep 17 00:00:00 2001
From: akallabeth <akallabeth@posteo.net>
Date: Thu, 10 Nov 2022 15:54:28 +0100
Subject: [PATCH] [winpr, crt] Added wcsstr implementation

(cherry picked from commit 6c034ba6117a4efc9266e845fe9a9a92ed4ee61d)
---
 winpr/include/winpr/string.h |  3 +++
 winpr/libwinpr/crt/string.c  | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/winpr/include/winpr/string.h b/winpr/include/winpr/string.h
index 3b907c444..2d7126210 100644
--- a/winpr/include/winpr/string.h
+++ b/winpr/include/winpr/string.h
@@ -62,6 +62,8 @@ extern "C"
 	WINPR_API size_t _wcslen(const WCHAR* str);
 	WINPR_API size_t _wcsnlen(const WCHAR* str, size_t maxNumberOfElements);
 
+	WINPR_API WCHAR* _wcsstr(const WCHAR* str, const WCHAR* strSearch);
+
 	WINPR_API WCHAR* _wcschr(const WCHAR* str, WCHAR c);
 	WINPR_API WCHAR* _wcsrchr(const WCHAR* str, WCHAR c);
 
@@ -74,6 +76,7 @@ extern "C"
 #define _wcsncmp wcsncmp
 #define _wcslen wcslen
 #define _wcsnlen wcsnlen
+#define _wcsstr wcsstr
 #define _wcschr wcschr
 #define _wcsrchr wcsrchr
 
diff --git a/winpr/libwinpr/crt/string.c b/winpr/libwinpr/crt/string.c
index 5dcf4b3f1..efd7d166c 100644
--- a/winpr/libwinpr/crt/string.c
+++ b/winpr/libwinpr/crt/string.c
@@ -147,6 +147,26 @@ size_t _wcsnlen(const WCHAR* str, size_t max)
 	return x;
 }
 
+/* _wcsstr -> wcsstr */
+
+WCHAR* _wcsstr(const WCHAR* str, const WCHAR* strSearch)
+{
+	assert(str);
+	assert(strSearch);
+
+	if (strSearch[0] == '\0')
+		return str;
+
+	const size_t searchLen = _wcslen(strSearch);
+	while (*str)
+	{
+		if (_wcsncmp(str, strSearch, searchLen) == 0)
+			return str;
+		str++;
+	}
+	return NULL;
+}
+
 /* _wcschr -> wcschr */
 
 WCHAR* _wcschr(const WCHAR* str, WCHAR c)
-- 
2.37.1