1 /* 2 * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <stddef.h> 8 #include <string.h> 9 strstr(const char * haystack,const char * needle)10char *strstr(const char *haystack, const char *needle) 11 { 12 const char *h = NULL; 13 size_t needle_len = 0; 14 15 if (needle[0] == '\0') 16 return (char *)haystack; 17 18 needle_len = strlen(needle); 19 for (h = haystack; (h = strchr(h, needle[0])) != 0; h++) 20 if (strncmp(h, needle, needle_len) == 0) 21 return (char *)h; 22 23 return NULL; 24 } 25