strtomem_pad(9)
π strtomem_pad(9) β the kernel API manual, bestie edition π
okay so this is strtomem_pad(9), and honestly? she's that girl. let's get into it β¨
πΈ NAME πΈ
strtomem_pad β copy a NUL-terminated string into a buffer that is not NUL-terminated. yes, you read that right, no cap π
β¨ SYNOPSIS β¨
strtomem_pad (dest , src , pad );
π¦ ARGUMENTS π¦
destβ pointer to the destination character array, and it's marked as__nonstring(iykyk). she's just built different, she does not do NUL termination π«Άsrcβ pointer to a NUL-terminated string. the source does have her little terminator, so bestie's got bounds to check against πpadβ the padding character used to fill any remaining bytes ofdestafter the copy. filler queen π
π₯ DESCRIPTION π₯
so this one is a replacement for strncpy uses where the destination is not a NUL-terminated string β but (and this is the iconic part) with bounds checking on the source size and an explicit padding character. obsessed.
if padding is not required, use strtomem instead. it's giving "less is more" π
β οΈ note that the size ofdestis not an argument β because the length ofdestmust be discoverable by the compiler. literally non-negotiable, the compiler has to know, periodt π
π SEE ALSO π
Kernel file ./include/linux/string.h, plus the whole friend group: memdup_array_user(9), vmemdup_array_user(9), strscpy(9), strscpy_pad(9), mem_is_zero(9), sysfs_match_string(9), memzero_explicit(9), kbasename(9), strtomem(9), memtostr(9), memtostr_pad(9), memset_after(9), memset_startat(9), str_has_prefix(9), strstarts(9), strends(9) π§π
and that's the whole vibe check π this one lives over in ./include/linux, straight from the October 2026 crew β mwah, slay, go forth and pad responsibly β¨ππ¦
π¦ 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