__sysfs_match_string(9)
π
__sysfs_match_string(9) β the Kernel API Manual, but make it make sense
okay so bestie, this is a kernel API page, and the whole thing lives in the Kernel API Manual. it's short, it's sweet, and it's lowkey doing more than it looks. let's get into it π«Ά
β¨ NAME β¨
__sysfs_match_string β matches a given string in an array π«
πΈ SYNOPSIS πΈ
int __sysfs_match_string (const char * const *array , size_t n , const
char *str );
yes. that's the whole signature. it's giving "small function, big job" energy and honestly? obsessed.
π ARGUMENTS π
arrayβ the array of strings, i.e. your little lineup of candidates πnβ how many strings are in the array, or-1for NULL-terminated arrays. yes,-1is a real value here, not a typo, don't come for me πstrβ the string you're trying to match π
π¦ DESCRIPTION π¦
So here's the tea: it returns the index of str in the array, or -EINVAL β just like match_string. periodt. the one difference that matters is that it uses sysfs_streq instead of strcmp for matching. that's the whole vibe shift, and it's iconic.
This routine will look for a string in an array of strings up to the n-th element in the array, or until the first NULL element. either way, the search is over π
Historically, the value of -1 for n was used to search in arrays that are NULL terminated. BUT β and this is the important part, bestie, don't skip it π¨ β the function does not make a distinction when finishing the search: either n elements have been compared OR the first NULL element was found. so don't go thinking the function knows which mode you meant, because it doesn't. it just stops. no cap.
π SEE ALSO π
the whole friend group, assembled π«Ά β all of these live in the kernel file ./lib/string_helpers.c:
string_get_size(9)parse_int_array_user(9)string_unescape(9)string_escape_mem(9)kasprintf_strarray(9)kfree_strarray(9)skip_spaces(9)strim(9)sysfs_streq(9)match_string(9)strreplace(9)memcpy_and_pad(9)
and that's the page, bestie β¨ this one comes to you from ./lib, dated October 2026 π go forth and match those strings, iykyk π
π¦
π¦ 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