bpf_strrchr(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… bpf_strrchr β€” like, the last one, bestie

okay so real talk, this is a page from the Kernel API Manual (manual name: bpf_strrchr(9), kernel section 9, we're in the big-leagues docs rn) and it's literally just "find the last time this character shows up in a string." that's it. that's the whole vibe. but she's a BPF kfunc so we're gonna read her properly πŸ’–


✨ NAME ✨

bpf_strrchr β€” Find the last occurrence of a character in a string

like strrchr but for BPF. the double-r is giving "reverse, babe." got it? πŸŽ€


🌸 SYNOPSIS 🌸

__bpf_kfunc int bpf_strrchr (const char *s__ign , int c );

yes the parameter really is spelled s__ign with the double underscore, that's not a typo, that's just how the kernel names its kfunc args, don't @ me πŸ™ˆ


πŸ¦‹ ARGUMENTS πŸ¦‹

  • s__ign β€” The string to be searched. she's the main character, we're looking through her πŸ‘‘
  • c β€” The character to search for. the little guy we're hunting for πŸ’…

πŸ”₯ RETURN πŸ”₯

she returns an int, and the number tells you a whole story:

  • >=0 β€” Index of the last occurrence of c within s__ign βœ… slay, found her, and she's at this position
  • -ENOENT β€” c not found in s__ign 😭 she's just not there, sorry bestie
  • -EFAULT β€” Cannot read s__ign πŸ’€ couldn't even read the string, tragic
  • -E2BIG β€” s__ign is too large 🫠 that string is doing too much
  • -ERANGE β€” s__ign is outside of kernel address space 🌈 wrong neighborhood entirely
ngl the negative returns are all error codes, so always check before you go indexing into stuff, fr fr πŸ™

⭐ SEE ALSO ⭐

Kernel file ./kernel/bpf/helpers.c, plus a whole friend group of kfuncs that want to be mentioned too:

bpf_obj_new(9), bpf_percpu_obj_new(9), bpf_obj_drop(9), bpf_percpu_obj_drop(9), bpf_refcount_acquire(9), bpf_list_push_front(9), bpf_list_push_back(9), bpf_rbtree_add(9), bpf_task_acquire(9), bpf_task_release(9), bpf_cgroup_acquire(9), bpf_cgroup_release(9), bpf_cgroup_ancestor(9), bpf_cgroup_from_id(9), bpf_task_under_cgroup(9), bpf_task_get_cgroup1(9), bpf_task_from_pid(9), bpf_task_from_vpid(9), bpf_dynptr_slice(9), bpf_dynptr_slice_rdwr(9), bpf_dynptr_copy(9), bpf_dynptr_memset(9), bpf_iter_bits_new(9), bpf_iter_bits_next(9), bpf_iter_bits_destroy(9), bpf_copy_from_user_str(9), bpf_copy_from_user_task_str(9), bpf_strcmp(9), bpf_strcasecmp(9), bpf_strnchr(9), bpf_strchr(9), bpf_strchrnul(9), bpf_strnlen(9), bpf_strlen(9), bpf_strspn(9), bpf_strcspn(9), bpf_strstr(9), bpf_strcasestr(9), bpf_strnstr(9), bpf_strncasestr(9), bpf_lookup_user_key(9), bpf_lookup_system_key(9), bpf_key_put(9), bpf_verify_pkcs7_signature(9), bpf_task_work_schedule_signal(9), bpf_task_work_schedule_resume(9), bpf_timer_cancel_async(9)

the string-function section of the group chat is honestly so iconic, bpf_strchr and bpf_strnchr are right there being the same but different πŸ’œ


mwah, that's the page 🫢 this one shipped out of ./kernel/bpf in October 2026 and she stays cute. go find your last character, bestie, periodt πŸ’…βœ¨

πŸ“¦ where this page comes from