MCPcopy Create free account
hub / github.com/coreboot/coreboot / strstr

Function strstr

payloads/libpayload/libc/string.c:267–280  ·  view source on GitHub ↗

* Find a substring within a string. * * @param h The haystack string. * @param n The needle string (substring). * @return A pointer to the first occurrence of the substring in * the string, or NULL if the substring was not encountered within the string. */

Source from the content-addressed store, hash-verified

265 * the string, or NULL if the substring was not encountered within the string.
266 */
267char *strstr(const char *h, const char *n)
268{
269 size_t hn = strlen(h);
270 size_t nn = strlen(n);
271
272 if (hn < nn)
273 return NULL;
274
275 for (size_t i = 0; i <= hn - nn; i++)
276 if (!memcmp(&h[i], n, nn))
277 return (char *)&h[i];
278
279 return NULL;
280}
281
282/**
283 * Separate strings.

Callers

nothing calls this directly

Calls 2

strlenFunction · 0.85
memcmpFunction · 0.70

Tested by

no test coverage detected