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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms