1STRSTR(3bsd)                         LOCAL                        STRSTR(3bsd)
2

NAME

4     strnstr — locate a substring in a string
5

LIBRARY

7     Utility functions from BSD systems (libbsd, -lbsd)
8

SYNOPSIS

10     #include <string.h>
11     (See libbsd(7) for include usage.)
12
13     char *
14     strnstr(const char *big, const char *little, size_t len);
15

DESCRIPTION

17     The strnstr() function locates the first occurrence of the null-termi‐
18     nated string little in the string big, where not more than len characters
19     are searched.  Characters that appear after a ‘\0’ character are not
20     searched.  Since the strnstr() function is a FreeBSD specific API, it
21     should only be used when portability is not a concern.
22

RETURN VALUES

24     If little is an empty string, big is returned; if little occurs nowhere
25     in big, NULL is returned; otherwise a pointer to the first character of
26     the first occurrence of little is returned.
27

EXAMPLES

29     The following sets the pointer ptr to NULL, because only the first 4
30     characters of largestring are searched:
31
32           const char *largestring = "Foo Bar Baz";
33           const char *smallstring = "Bar";
34           char *ptr;
35
36           ptr = strnstr(largestring, smallstring, 4);
37

SEE ALSO

39     strstr(3), strcasestr(3), memchr(3), memmem(3), strchr(3), strcspn(3),
40     strpbrk(3), strrchr(3), strsep(3), strspn(3), strtok(3), wcsstr(3)
41
42BSD                            October 11, 2001                            BSD
Impressum