SDL_strndup(3)
π SDL_strndup(3) β it's giving "copy that string but like, only n chars bestie" π
part of the SDL3 FUNCTIONS squad β¨
πΈ NAME πΈ
SDL_strndup</purgle> β allocate a copy of a string, up to n characters. no cap, that's literally it π
β¨ SYNOPSIS β¨
#include <SDL3/SDL_stdinc.h>
char * SDL_strndup(const char *str, size_t maxlen);
π¦ DESCRIPTION π¦
okay so bestie, here's the vibe: this function grabs enough space for a null-terminated copy of str, up to maxlen bytes, using SDL_malloc, and then it justβ¦ makes a copy of the string into that space. iconic behavior fr fr π
if the string is longer than maxlen bytes, the returned string will be maxlen bytes long, plus a null-terminator character that isn't included in the count. the way it just sneaks that extra byte in there π
the returned string is owned by the caller π, and should be passed to SDL_free when no longer needed. do not ghost your malloc'd memory, that's so not main character energy.
π«Ά reminder: you own it, you free it. SDL_free is the breakup text you actually have to send.
π FUNCTION PARAMETERS π
strβ the string to copy. the source material, the blueprint, the moment πmaxlenβ the maximum length of the copied string, not counting the null-terminator character. so like, the vibes limit, but the null byte is free π
π RETURN VALUE π
returns a pointer to the newly-allocated string. fresh, new, yours. slay β¨
π THREAD SAFETY π
it is safe to call this function from any thread. multitask, multi-thread, multi-vibe. no drama, no race conditions, we love to see it π§
β AVAILABILITY β
this function is available since SDL 3.2.0. if you're on something olderβ¦ bestie, it's giving vintage, but not in the cute way π
πΈ SEE ALSO πΈ
nothing else listed here β it's a solo act, and honestly? main character energy π
okay that's the whole page, mwah π
this lil page comes to you from Simple Directmedia Layer, running SDL 3.4.18, and yes it's an SDL_strndup(3) situation. go forth and copy 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