kstrndup(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

kstrndup(9) πŸ’…

okay so bestie, welcome to the Kernel API Manual page for kstrndup(9) β€” manual name folded in near the top like a little name tag, we're not doing the copy-paste header thing ✨

πŸŽ€ NAME πŸŽ€

kstrndup β€” allocate space for and copy an existing string. That's the whole vibe: it grabs memory and duplicates a string for you. periodt.

🌸 SYNOPSIS 🌸

char * kstrndup (const char *s , size_t max , gfp_t gfp );

✨ ARGUMENTS ✨

  • s β€” the string to duplicate. Like, the original string bestie, the one you want a copy of.
  • max β€” read at most max chars from s. There is literally a cap, and the cap is max.
  • gfp β€” the GFP mask used in the kmalloc call when allocating memory. That's the allocation vibe check for this function.

🫢 NOTE 🫢

Use kmemdup_nul instead if the size is known exactly. Not me telling you what to do, just the manpage telling you what to do πŸ’…

πŸ”₯ RETURN πŸ”₯

newly allocated copy of s or NULL in case of error. So you either get the duplicate or a NULL situation, and that's the whole return story.

πŸ¦‹ SEE ALSO πŸ¦‹

Kernel file ./mm/util.c and all these besties:


mwah πŸ’‹ this one lives under ./mm, dated October 2026, and yes it's all about kstrndup(9) β€” bye bestie 🫢

πŸ“¦ where this page comes from