kstrndup(9)
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 mostmaxchars froms. There is literally a cap, and the cap ismax.gfpβ the GFP mask used in thekmalloccall 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:
kfree_const(9)__kmemdup_nul(9)kstrdup(9)kstrdup_const(9)kmemdup(9)kmemdup_array(9)kvmemdup(9)kmemdup_nul(9)memdup_user(9)vmemdup_user(9)strndup_user(9)memdup_user_nul(9)randomize_page(9)__account_locked_vm(9)account_locked_vm(9)__vmalloc_array(9)vmalloc_array(9)__vcalloc(9)vcalloc(9)folio_mapping(9)folio_copy(9)get_cmdline(9)mem_dump_obj(9)compat_set_desc_from_vma(9)__compat_vma_mmap(9)compat_vma_mmap(9)snapshot_page(9)mmap_action_prepare(9)mmap_action_complete(9)folio_pte_batch(9)page_range_contiguous(9)
mwah π this one lives under ./mm, dated October 2026, and yes it's all about kstrndup(9) β bye bestie π«Ά
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms