__sysfs_match_string(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… __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 -1 for NULL-terminated arrays. yes, -1 is 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:


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