bpf_strrchr(9)
π 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 ofcwithins__ignβ slay, found her, and she's at this position-ENOENTβcnot found ins__ignπ she's just not there, sorry bestie-EFAULTβ Cannot reads__ignπ couldn't even read the string, tragic-E2BIGβs__ignis too large π« that string is doing too much-ERANGEβs__ignis 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
- 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