nla_strscpy(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– nla_strscpy(9) β€” the kernel API manual, bestie edition πŸ’–

okay so you found your way into the nla_strscpy(9) page, welcome, this is the kernel API manual and we're gonna get you fluent in it, no cap 🫢


✨ NAME ✨

nla_strscpy β€” copy a string attribute payload into a sized buffer. that's it, that's the whole vibe πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

ssize_t nla_strscpy (char *dst , const struct nlattr *nla , size_t
dstsize );

like, look at her. iconic signature. three args, one return type, zero drama ⭐


🌸 ARGUMENTS 🌸

  • dst β€” where the string gets copied to. your destination. the place she's moving into 🏠
  • nla β€” the attribute you're copying the string from. the source of truth, the origin story πŸ’«
  • dstsize β€” the size of the destination buffer. how much room dst actually has. respect the boundary bestie πŸ™ˆ

πŸŽ€ DESCRIPTION πŸŽ€

so what does she do. she copies at most dstsize - 1 bytes into the destination buffer. that "-1" is not a typo, that's the NUL terminator reserving its little seat, periodt πŸ’€

and here's the glow-up: unlike strscpy, the destination buffer is always padded out. literally always. she does not skip the padding, she does not half-do it, she pads. main character energy πŸ”₯


πŸ‘‘ RETURN πŸ‘‘

  • srclen β€” returns the nla length, and just so we're clear that's not including the trailing NUL. the NUL is not invited to the count 🚫
  • -E2BIG β€” returned if dstsize is 0, or dstsize is greater than U16_MAX, or the nla length is greater than dstsize. too big, too small, wrong vibe, she's saying no 😭

🌈 SEE ALSO 🌈

the whole friend group, fr fr β€” kernel file ./lib/nlattr.c, __nla_validate(9), nla_policy_len(9), __nla_parse(9), nla_find(9), nla_strdup(9), nla_memcpy(9), nla_memcmp(9), nla_strcmp(9), __nla_reserve(9), __nla_reserve_64bit(9), __nla_reserve_nohdr(9), nla_reserve(9), nla_reserve_64bit(9), nla_reserve_nohdr(9), __nla_put(9), __nla_put_64bit(9), __nla_put_nohdr(9), nla_put(9), nla_put_64bit(9), nla_put_nohdr(9), nla_append(9) πŸ¦‹


and that's the page!! mwah πŸ’‹ this one lives in ./lib, dated October 2026, and it's nla_strscpy(9) signing off β€” go pad a buffer responsibly, ily πŸ§šπŸ’œ

πŸ“¦ where this page comes from