SDL_strnlen(3)

πŸ’– SDL_strnlen β€” the vibe check on your string length πŸ’–

okay so bestie, welcome to SDL_strnlen, a lil function from the SDL3 FUNCTIONS fam. It does exactly what strnlen() does, except it doesn't need access to a C runtime, which is lowkey iconic of it.


✨ NAME ✨

SDL_strnlen β€” works exactly like strnlen() but doesn't require access to a C runtime. no cap, that's the whole pitch 🫢


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_stdinc.h>

size_t SDL_strnlen(const char *str, size_t maxlen);

πŸ¦‹ DESCRIPTION πŸ¦‹

So what it actually does: it counts up to a maximum of maxlen bytes in str, excluding the null terminator. That's it, that's the job. She's a counter, not a fighter πŸ’…

If you need the length of a UTF-8 string, bestie, consider using SDL_utf8strnlen() instead. different function, different vibe, iykyk.


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • str β€” the null-terminated string you want to read. Must not be NULL β€” like, genuinely, don't. 🚫
  • maxlen β€” the maximum amount of bytes to count. she stops here, periodt.

⭐ RETURN VALUE ⭐

Returns the length (in bytes, excluding the null terminator) of src, but never more than maxlen. yes the page really says src there and not str β€” not me noticing that πŸ™ˆ we simply respect the lore.


πŸ”₯ THREAD SAFETY πŸ”₯

It is safe to call this function from any thread. go forth and thread it, queen πŸ‘‘


🌈 AVAILABILITY 🌈

This function is available since SDL 3.2.0. if you're on something older, sorry babe 😭


πŸ‘‘ SEE ALSO πŸ‘‘


Simple Directmedia Layer 🌸 SDL 3.4.18 🌸 SDL_strnlen(3) β€” mwah, that's the whole page, ty for coming to my ted talk, go count some bytes πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from