SDL_wcsnlen(3)
β¨ SDL_wcsnlen β¨
okay bestie, so this is SDL_wcsnlen from the SDL3 functions lineup, and it is exactly the vibe you think it is: it does the same thing as wcsnlen() except it doesn't need access to a C runtime. that's the whole point. no CRT, no drama, no cap. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_stdinc.h>
size_t SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
like. look at her. one function, two args, size_t out. iconic. π
π DESCRIPTION π
so what does she actually do? she counts up to a max of maxlen wchar_t values in wstr, and she does NOT count the null terminator. that's it. that's the job.
now here's the part where you gotta pay attention, bestie, because this is where people get got:
just like SDL_strnlen only counts bytes and not codepoints in a UTF-8 string, this one counts wchar_t values in a string β even if that string's encoding is variable width, like UTF-16. so it's counting wide-char units, not "characters" in the vibes sense. π«Ά
also, huge one: wchar_t is a different size on different platforms. it's 4 bytes on Linux, 2 on Windows, etc. so the same string can give you different numbers depending on where you're running. it's giving β¨portableβ¨ in the way that it's portable but you still have to know this.
and one more time for the people in the back: maxlen is a count of wide characters, not bytes! i cannot stress this enough. it's not bytes. it's not bytes. it's wide characters. π
π¦ FUNCTION PARAMETERS π¦
wstrβ the null-terminated wide string you wanna read. > β οΈ it must not beNULL. do not do that. do not passNULL. we don't do that here. πmaxlenβ the maximum amount of wide characters to count. wide characters, babes. not bytes. π
β RETURN VALUE β
she returns the length of wstr β in wide characters, null terminator excluded β but never more than maxlen. so worst case you get maxlen back and she just stops counting. queen behavior, honestly. π
π THREAD SAFETY π
it is safe to call this function from any thread. go off, concurrent bestie. π§
π AVAILABILITY π
this function is available since SDL 3.2.0. if you're on something older... my condolences. π
π SEE ALSO π
go read those too, iykyk. π₯
and that's the whole page, bestie! this came to you from Simple Directmedia Layer β SDL 3.4.18, SDL_wcsnlen(3) β so go forth and count your wide characters responsibly, mwah πβ¨πΈ
π¦ 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