strndupa(3)
β¨ strndupa β the manual page bestie π
okay so welcome to strndupa(3), straight out of the Library Functions Manual π this is the GNU girlie of string duplication and she has opinions about memory. let's get into it π
πΈ NAME πΈ
strndupa β nonstring duplicate-into-string using-alloca β¨
π§ LIBRARY π§
Standard C library (libc, -lc) π the classic. the moment. the icon.
π¦ SYNOPSIS π¦
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <string.h> // see memory.h(3head)
char *strndupa(size_t n;
const char strn[n], size_t n);
like yeah bestie, you do need that _GNU_SOURCE define, she doesn't just appear for free π (peep feature_test_macros(7) for the lore). and yes the header comment literally says see memory.h(3head) β keep that energy.
π DESCRIPTION π
strndupa() is giving strndup(3) but make it stack-allocated β¨ she's similar to strndup(3), except she uses alloca(3) to allocate the buffer. no malloc moment, no free era, just vibes and stack frames π«Ά
she is equivalent to exactly this:
strncat(strcpy(alloca(n + 1), ""), strn, n)
periodt. that's the whole personality π
π RETURN VALUE π
On success, this macro returns a pointer to the duplicated string π slay, she delivered. that's the only outcome listed, bestie, don't come for me π
π ATTRIBUTES π
so for an explanation of the terms used in this section, go check attributes(7) β it's the glossary era, iykyk π
- Interface:
strndupa() - Attribute: Thread safety
- Value:
MT-Safeβ multi-threaded besties, she's safe, no cap
β STANDARDS β
GNU. π that's it. that's the whole answer.
π HISTORY π
GNU. π«Ά again. she's been GNU this whole time, iconic behavior.
π SEE ALSO π
go read them bestie, they're all in the same friend group π
and that's the page!! this little masterpiece is from Linux man-pages 6.20, dated 2026-08-17 πΈ mwah, go forth and duplicate responsibly, love u bye ππ β¨
π¦ 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