kstrtol(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 is 16, so don't come at her with base 17, she's not doing it πŸ™ˆ. but here's the cute part: if base is given as 0, then the base of the string is automatically detected with the conventional semantics β€” like, she reads the room πŸ’…:
    • if it begins with 0x the number will be parsed as a hexadecimal (case insensitive, she doesn't care if you scream 0X or whisper 0x)
    • if it otherwise begins with 0, it will be parsed as an octal number
    • otherwise it will be parsed as a decimal
  • 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 🌈

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