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 a SDL_malloc'd null-terminated copy back, SDL_free it 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