strnlen_user(9)
π strnlen_user(9) π
okay bestie, welcome to the strnlen_user glow-up β¨ this one lives in the Kernel API Manual and honestly? it's giving "small function, big opinions." let's get into it π«Ά
π NAME π
strnlen_user β get the size of a user string INCLUDING the final NUL. literally what it says on the tin π
β¨ SYNOPSIS β¨
long strnlen_user (const char __user *str , long count );
like yes, that's the whole signature, she's compact π
πΈ ARGUMENTS πΈ
strβ the string you want measured, bestie. that's it, that's the vibe πcountβ the maximum count (including theNULcharacter). so like, the ceiling, the limit, the "don't go past this" energy π§
π¦ CONTEXT π¦
User context only. and heads up β this function may sleep if pagefaults are enabled π΄ so don't be calling it from somewhere weird, iykyk.
π DESCRIPTION π
okay so the actual job: get the size of a NUL-terminated string in user space.
It returns the size of the string INCLUDING the terminating NUL. cute, right?
But β if the string is too long, it returns a number larger than count. so the user has to check the return value against > count π do not skip the vibe check on that return value, fr fr.
On exception (or an invalid count), it returns 0. π
β οΈ NOTE! You should basically never use this function. like, genuinely. There is almost never any valid case for using the length of a user space string, since the string can be changed at any time by other threads π it's a moving target, bestie. Use strncpy_from_user instead to get a stable copy of the string. that's the main character move π
π SEE ALSO π
- Kernel file
./lib/strnlen_user.cπ
and that's the whole page, no cap β¨ this little icon comes to you from ./lib, October 2026 edition π§ββοΈ go forth and use strncpy_from_user instead, bestie, ily πππ¦
π¦ 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