SDL_strlcpy(3)
π SDL_strlcpy β from the SDL3 FUNCTIONS manual, bestie π
β¨ NAME β¨
SDL_strlcpy β copy a string, but like, safely. no cap. π«Ά
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_stdinc.h>
size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen);
π¦ DESCRIPTION π¦
okay so here's the vibe. SDL_strlcpy copies up to maxlen - 1 characters from src into dst, and then it appends a null terminator. that's it. that's the whole thing. iconic behaviour honestly. π
but listen, the edge cases are where it gets real:
- if
maxlenis0, no characters are copied and no null terminator is written. nothing happens. it's giving "i'm not doing that" energy. π - if you're copying a UTF-8 string and you need to make sure multi-byte sequences don't get chopped mid-character (which would be so embarrassing for everyone involved π), consider using
SDL_utf8strlcpy()instead. she's the specialist for that job. β¨
π FUNCTION PARAMETERS π
dstβ the destination buffer. she must not beNULL, and she must not overlap withsrc. two queens can't share the same spotlight, ok? πsrcβ the null-terminated string you're copying from. also must not beNULL, and also must not overlap withdst. the boundaries are boundaries. π§maxlenβ the length (in characters) of the destination buffer. basically: how much room doesdsthave? that's your budget, bestie, spend it wisely. πΈ
β RETURN VALUE β
it returns the length (in characters, excluding the null terminator) of src. so like, the source length, not the amount copied. important distinction, don't get it twisted. π§
π THREAD SAFETY π
it is safe to call this function from any thread. yes ma'am, thread-safe, we love a low-maintenance function. π«Ά
π AVAILABILITY π
this function is available since SDL 3.2.0. if you're on something older... bestie. update. π
π SEE ALSO π
psa:dstcan't beNULL,srccan't beNULL, and they can't overlap. that's not a suggestion, that's the rule. π
okay that's the whole page, slay. this was SDL_strlcpy(3) from the Simple Directmedia Layer crew, page version SDL 3.4.18 β mwah, go write some safe string copies, you absolute main character. πβ¨ππ¦πΈ
π¦ 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