strstr(3bsd)
π strstr(3bsd) β the LOCAL girlies' guide π
okay so bestie, welcome to strstr(3bsd), from the <cyan>LOCAL</cyan> section β yes she's local, she's niche, she's that girl π
β¨ NAME β¨
strnstr β locate a substring in a string π
π LIBRARY π
Utility functions from BSD systems, aka libbsd, and you link her with -lbsd π
π§ SYNOPSIS π§
#include <string.h>
(See libbsd(7) for include usage.)
char *
strnstr(const char *big, const char *little, size_t len);
yes you literally need to peep libbsd(7) for the include usage, i don't make the rules, i just report them π«Ά
πΈ DESCRIPTION πΈ
so the way strnstr() works is: she goes looking for the first occurrence of the null-terminated string little inside the string big, and she only searches not more than len characters. that's the whole vibe check β¨
anything that shows up after a '\0' character? not searched. periodt. she stops caring right there π
and listen β strnstr() is a FreeBSD specific API, so it should only be used when portability is not a concern. if you're trying to be portable bestie, this is not the function for you π
π RETURN VALUES π
here's the tea on what she gives you back:
- if little is an empty string, you get big back. iconic behavior honestly π
- if little occurs nowhere in big, you get
NULL. sad. tragic. we move on π - otherwise? you get a pointer to the first character of the first occurrence of little. slay β¨π
π¦ EXAMPLES π¦
okay so this next one sets the pointer ptr to NULL, because only the first 4 characters of largestring are searched. watch π
const char *largestring = "Foo Bar Baz";
const char *smallstring = "Bar";
char *ptr;
ptr = strnstr(largestring, smallstring, 4);
she searched four characters. "Bar" was not in those four characters. therefore: NULL. no cap. π
π SEE ALSO π
strstr(3)strcasestr(3)memchr(3)memmem(3)strchr(3)strcspn(3)strpbrk(3)strrchr(3)strsep(3)strspn(3)strtok(3)wcsstr(3)
a whole friend group honestly, go say hi π«Ά
π HISTORY π
strnstr() originated in FreeBSD. her origin story, her lore, her main character energy π
kisses bestie, this page came to you from Debian, dated October 11, 2001 β yes she's been serving since 2001 and she's still eating π β¨ mwah π
π¦ where this page comes from
- alpine 3.22: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.23: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.24: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- arch rolling: libbsd 0.12.2-2 Β· custom
- debian trixie: libbsd-dev 0.12.2-2
- epel 10: libbsd-devel 0.12.2-4.el10_0 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- epel 9: libbsd-devel 0.12.2-1.el9 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- nixos 26.05: libbsd 0.12.2
- ubuntu noble: libbsd-dev 0.12.1-1build1
- ubuntu noble: libbsd-dev 0.12.1-1build1.1
- ubuntu questing: libbsd-dev 0.12.2-2build1
- ubuntu resolute: libbsd-dev 0.12.2-2build2
- ubuntu stonking: libbsd-dev 0.12.2-3
- Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
- Copyright (c) 1990, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms