SDL_utf8strlcpy(3)
SDL_utf8strlcpy π
okay bestie, this is a SDL3 FUNCTIONS page, and it's genuinely one of the good ones. sit down, hydrate, let's go β¨
β¨ NAME β¨
SDL_utf8strlcpy β copy a UTF-8 string, but make it safe π
β¨ SYNOPSIS β¨
#include <SDL3/SDL_stdinc.h>
size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
β¨ DESCRIPTION β¨
so the way this works is: it copies up to dst_bytes - 1 bytes from src to dst, and it also makes sure the string it writes into dst doesn't end in a truncated multi-byte sequence. like, no half-characters left dangling, we don't do that here π«Ά. then it appends a null terminator, as one does.
src and dst must not overlap. no cap, they just can't.
heads up bestie: unlikeSDL_strlcpy(), this function returns the number of bytes written, not the length ofsrc. it's giving "similar name, different vibe" π
β¨ FUNCTION PARAMETERS β¨
dstβ the destination buffer. must not beNULL, and must not overlap withsrc. πsrcβ the null-terminated UTF-8 string you're copying. must not beNULL, and must not overlap withdst. π¦dst_bytesβ the length (in bytes) of the destination buffer. must not be0. zero is not the move, babe.
β¨ RETURN VALUE β¨
returns the number of bytes written, excluding the null terminator. that's it, that's the tea π
β¨ THREAD SAFETY β¨
it is safe to call this function from any thread. queen behavior, honestly π
β¨ AVAILABILITY β¨
this function is available since SDL 3.2.0. if you're on something older, it's simply not there, sorry babe π
β¨ SEE ALSO β¨
Simple Directmedia Layer π SDL 3.4.18 β mwah, that's the whole page, go forth and copy your UTF-8 strings responsibly, bestie πβ¨π
π¦ 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