Add strstr implementation
Implement custom strstr function.
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: Id5998fb9c3797f9a35aa40aedbd8cac8d56cf895
diff --git a/components/common/libc/include/string.h b/components/common/libc/include/string.h
index 8129404..135e443 100644
--- a/components/common/libc/include/string.h
+++ b/components/common/libc/include/string.h
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
- * Portions copyright (c) 2018-2020, Arm Limited and Contributors.
+ * Portions copyright (c) 2018-2024, Arm Limited and Contributors.
* Portions copyright (c) 2023, Intel Corporation. All rights reserved.
* All rights reserved.
*/
@@ -30,5 +30,6 @@
size_t strlcpy(char * dst, const char * src, size_t dsize);
size_t strlcat(char * dst, const char * src, size_t dsize);
char *strtok_r(char *s, const char *delim, char **last);
+char *strstr(const char *haystack, const char *needle);
#endif /* STRING_H */
diff --git a/components/common/libc/src/strstr.c b/components/common/libc/src/strstr.c
new file mode 100644
index 0000000..0192d0f
--- /dev/null
+++ b/components/common/libc/src/strstr.c
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stddef.h>
+#include <string.h>
+
+char *strstr(const char *haystack, const char *needle)
+{
+ const char *h = NULL;
+ size_t needle_len = 0;
+
+ if (needle[0] == '\0')
+ return (char *)haystack;
+
+ needle_len = strlen(needle);
+ for (h = haystack; (h = strchr(h, needle[0])) != 0; h++)
+ if (strncmp(h, needle, needle_len) == 0)
+ return (char *)h;
+
+ return NULL;
+}