kstrtol(9)
π kstrtol(9) β the manual page, but make it make sense
okay so bestie, this is kstrtol from the Kernel API Manual, and it's literally the glow-up version of turning a string into a long. no cap. let's get into it π«Ά
β¨ NAME β¨
kstrtol β convert a string to a long. that's it. that's the whole vibe check. π
πΈ SYNOPSIS πΈ
int kstrtol (const char *s , unsigned int base , long *res );
look at her. three args, one int coming back. iconic. π
π¦ ARGUMENTS π¦
sβ the start of the string. this is the main character of the whole function ngl. she must be null-terminated, and she may also include a single newline before her terminating null (just one, don't get greedy π). and listen β the first character may also be a plus sign or a minus sign. yes bestie, she's flexible like that β¨baseβ the number base to use. the maximum supported base is16, so don't come at her with base 17, she's not doing it π. but here's the cute part: ifbaseis given as0, then the base of the string is automatically detected with the conventional semantics β like, she reads the room π :- if it begins with
0xthe number will be parsed as a hexadecimal (case insensitive, she doesn't care if you scream0Xor whisper0x) - if it otherwise begins with
0, it will be parsed as an octal number - otherwise it will be parsed as a decimal
- if it begins with
resβ where to write the result of the conversion on success. this is the lil drop-off spot. she leaves the answer here π
π DESCRIPTION π
okay so here's the tea: returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. those are the only three plot twists π
this function is preferred over simple_strtol β she's the upgrade, the newer model, the one you actually want. and the return code must be checked. like, literally non-negotiable.
β οΈ bestie please. check that return code. i am begging. do not just call kstrtol and walk away like nothing happened π the return code must be checked. that's not a suggestion, that's the whole point.
π SEE ALSO π
- Kernel file:
./include/linux/kstrtox.h kstrtoul(9)
go read the header, she has lore π§
and that's the page, bestie π this gem lives with the rest of the kernel docs under ./include/linux, dated October 2026. slay, stay safe, and please check your return codes. 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