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 maxlen bytes πŸŽ€

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 be NULL. like, genuinely, do not.
  • needle β€” the string to search for. Must not be NULL. same energy, same rule.
  • maxlen β€” the maximum number of bytes to search in haystack. 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