SDL_strdup(3)
π SDL_strdup(3) β the SDL3 function that copies ur string, no cap π
okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, where today's main character is SDL_strdup. she's simple, she's reliable, she's giving "duplicate my string pls" energy. π¦
β¨ NAME β¨
SDL_strdup β Allocate a copy of a string. π
β¨ SYNOPSIS β¨
#include <SDL3/SDL_stdinc.h>
char * SDL_strdup(const char *str);
that's it. that's the whole vibe check. π
β¨ DESCRIPTION β¨
so here's the tea, bestie π β this function allocates enough space for a null-terminated copy of str, and it does that using SDL_malloc. then it literally makes a copy of the string into that space. boom. duplicated. iconic.
the returned string is owned by the caller, which means you are the responsible adult here π«Ά β when you're done with it and no longer need it, you should pass it to SDL_free. don't just ghost it, that's a memory leak and leaks are not the vibe. π
β¨ FUNCTION PARAMETERS β¨
strβ the string to copy. πβ¨ just hand her the string and she'll hand you back a fresh copy.
β¨ RETURN VALUE β¨
Returns a pointer to the newly-allocated string. fresh out of the allocator, still warm, ready to be yours. π
β¨ THREAD SAFETY β¨
It is safe to call this function from any thread. no drama, no fights, no locking discourse. she's chill in every thread, periodt. π§
β¨ AVAILABILITY β¨
This function is available since SDL 3.2.0. so if you're on something older... ngl, bestie, you're missing out. π
lowkey the whole thing is: give her a string, get aSDL_malloc'd null-terminated copy back,SDL_freeit when you're done. that's the entire arc. ate and left no crumbs. π₯
okay that's the page!! π brought to you by the Simple Directmedia Layer girlies, running SDL 3.4.18, and yeah this lil SDL_strdup(3) page is dated exactly like that too. mwah, take care of ur pointers 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