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
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms