SDL_strnstr(3)
π SDL_strnstr π
okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_strnstr β she finds your substring and she does it with a limit, which is honestly iconic behaviour β¨
πΈ NAME πΈ
SDL_strnstr β search a string, up to n bytes, for the first instance of a specific substring π¦
β¨ SYNOPSIS β¨
#include <SDL3/SDL_stdinc.h>
char * SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
π DESCRIPTION π
so here's the vibe: the search ends the second one of these three things happens β
- it finds the substring you asked for, or
- it hits a null terminator byte that ends the string, or
- it has examined
maxlenbytes π
which means β and this is the part that's giving very flexible, very generous β it is possible to use this function on a string without a null terminator. no terminator? no problem, she just counts bytes instead. periodt π
also note (lowkey important): this looks for strings of _bytes_, not _characters_. so it's totally legal to search for malformed and incomplete UTF-8 sequences. she does not judge your encoding, she does not fix it, she just matches bytes fr fr π
π«Ά FUNCTION PARAMETERS π«Ά
haystackβ the string to search. Must not beNULL. like, genuinely, do not.needleβ the string to search for. Must not beNULL. same energy, same rule.maxlenβ the maximum number of bytes to search inhaystack. this is your budget, bestie, spend it wisely β
π RETURN VALUE π
returns a pointer to the first instance of needle in the string, or NULL if it's not found π
π THREAD SAFETY π
it is safe to call this function from any thread. go off, multitask, she's not scared π
β AVAILABILITY β
this function is available since SDL 3.2.0 π
and that's the whole page, no cap π§ from your friends at Simple Directmedia Layer, version SDL 3.4.18 β this was the SDL_strnstr(3) manual page, ty for coming to my ted talk, ily, bye π
πΈ
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms