match_strdup(9)
π 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β thesubstring_tyou 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 πΈ:
match_one(9)match_token(9)match_number(9)match_u64int(9)match_int(9)match_uint(9)match_u64(9)match_octal(9)match_hex(9)match_wildcard(9)match_strlcpy(9)
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
- 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