match_strdup(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– match_strdup(9) β€” the kernel API manual, bestie edition πŸ’–

okay so real talk, this is a page from the Kernel API Manual and honestly? it's giving "tiny function, big main character energy" ✨ it's called match_strdup and it's lowkey one of the most useful little gremlins in the parser squad. let's get into it 🫢


🌸 NAME 🌸

match_strdup β€” allocate a new string with the contents of a substring_t πŸ’…

like... it literally makes you a fresh new string that's a copy of a substring. no cap, that's the whole vibe.


✨ SYNOPSIS ✨

char * match_strdup (const substring_t *s );

that's it. that's the whole signature. short, sweet, iconic πŸ‘‘


πŸŽ€ ARGUMENTS πŸŽ€

  • s β€” the substring_t you want to copy. literally just hand it the substring, bestie, and it'll do the thing πŸ¦‹

πŸ’œ DESCRIPTION πŸ’œ

okay so here's the tea β˜• β€” this function allocates and returns a string filled with the contents of the substring_t s. so you give it a substring, it gives you back a whole brand-new string with the same contents. it's giving copy-paste but make it kernel-level πŸ’«

but listen 🚨 β€” and this is the part you cannot skip β€” the caller is responsible for freeing the returned string with kfree. that's you. you're the caller. you have to kfree it. do not leave that string orphaned in memory, that's not the vibe, that's a leak 😭 the function does not clean up after itself, it just hands you the string and trusts you to be a responsible main character.


πŸ”₯ RETURN πŸ”₯

it returns the address of the newly allocated NUL-terminated string 🌈 β€” or NULL on error πŸ’€ so like, always check for NULL, please, for me? a NULL check is self-care, periodt.


πŸ¦‹ SEE ALSO πŸ¦‹

all the parser besties, in the kernel file ./lib/parser.c 🌸:

the whole squad, together. iykyk πŸ’…


🧚 cute little sign-off 🧚

this page lives in ./lib πŸ“ and it's dated October 2026 ⭐ β€” so yeah, future vibes, but the C is timeless. anyway, go forth, call match_strdup, and actually kfree the result, okay? i believe in you πŸ«ΆπŸ’–

match_strdup(9) β€” slay responsibly βœ¨πŸ‘‘

πŸ“¦ where this page comes from