strdupa(3)

✨ NAME ✨

strdupa β€” string duplicate but make it alloca πŸ’…

okay so bestie, real talk: this is the manual page for strdupa(3), living in the Library Functions Manual section. she's a little chaotic, she's stack-allocated, and she is absolutely not your normal strdup. let's get into it 🫢


πŸ“š LIBRARY πŸ“š

Standard C library β€” that's libc, link her with -lc πŸŽ€


✨ SYNOPSIS ✨

#define _GNU_SOURCE  /* See feature_test_macros(7) */
#include <string.h>

char *strdupa(const char *s);

yes bestie you read that right, you need that #define _GNU_SOURCE up top or she simply will not show up. check feature_test_macros(7) for the whole lore on that one πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

So. strdupa() is giving strdup(3) energy, except instead of malloc-ing your buffer, she uses alloca(3) to allocate it. same vibe, different memory neighborhood 🏘️

She is literally exactly equivalent to:

strcpy(alloca(strlen(s) + 1), s)

like that's it. that's the whole function. no cap. πŸ”₯


🎁 RETURN VALUE 🎁

On success, this macro hands you back a pointer to the duplicated string. slay. ✨


πŸ¦‹ ATTRIBUTES πŸ¦‹

For the deets on what all these terms even mean, go peek at attributes(7).

  • Interface: strdupa()
  • Attribute: Thread safety
  • Value: MT-Safe πŸ‘‘

so yes bestie, she's MT-Safe, she can hang with the threads πŸ’…


🌸 STANDARDS 🌸

GNU. that's it, that's the standard. periodt. πŸŽ€


⭐ HISTORY ⭐

Also GNU. iconic behavior, honestly. πŸ’œ


πŸ’€ CAVEATS πŸ’€

Go read alloca(3). seriously. this is not me being cute, this is me being real with you. everything terrifying about stack allocation applies here and she's not gonna say it twice πŸ™ˆ

bestie I am begging you, read alloca(3) before you ship this. stack memory does not play nice and it does not warn you first 😭

πŸ‘€ SEE ALSO πŸ‘€


and that's the whole page, bestie!! this one's from Linux man-pages 6.20, dated 2026-08-10, filed under strdupa(3). go forth and duplicate responsibly πŸ§šπŸ’–

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms