3 <<strnstr>>---find string segment
10 size_t strnstr(const char *<[s1]>, const char *<[s2]>, size_t <[n]>);
13 Locates the first occurrence in the string pointed to by <[s1]> of
14 the sequence of limited to the <[n]> characters in the string
18 Returns a pointer to the located string segment, or a null
19 pointer if the string <[s2]> is not found. If <[s2]> points to
20 a string with zero length, <[s1]> is returned.
24 <<strnstr>> is a BSD extension.
26 <<strnstr>> requires no supporting OS subroutines.
37 * Find the first occurrence of find in s, where the search is limited to the
38 * first slen characters of s.
41 strnstr(const char *haystack
, const char *needle
, size_t haystack_len
)
43 size_t needle_len
= strnlen(needle
, haystack_len
);
45 if (needle_len
< haystack_len
|| !needle
[needle_len
]) {
46 char *x
= memmem(haystack
, haystack_len
, needle
, needle_len
);
47 if (x
&& !memchr(haystack
, 0, x
- haystack
))