scnprintf(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… scnprintf(9) β€” the kernel API manual, but make it make sense

okay bestie, so this page is called scnprintf and it lives in the kernel API manual. it's literally "Format a string and place it in a buffer" β€” that's the whole vibe. a formatted string goes in, a buffer comes out, nobody gets hurt. ✨


✨ SYNOPSIS ✨

int scnprintf (char *buf , size_t size , const char *fmt , ... );

look at her. one line. four things. she's gorgeous and she's not even trying. πŸŽ€


🌸 ARGUMENTS 🌸

  • buf β€” the buffer where the result goes. this is the destination, the main character, the place the magic lands. πŸ’–
  • size β€” the size of that buffer, and yes, that includes the trailing null space. count it. do not forget it. this is the classic mistake and i will not be silent about it. πŸ™ˆ
  • fmt β€” the format string you're using. your template. your blueprint. πŸ¦‹
  • ... β€” the arguments for the format string. the little guys that get slotted in. there can be a bunch of them, that's the whole point of the ... πŸ’…

πŸ”₯ DESCRIPTION πŸ”₯

okay so here's the part that actually matters, bestie β€” the return value.

it's the number of characters actually written into buf, and it does not include the trailing '\0'. like, the terminator is not invited to the count. it's there, it's doing its job, but it's not on the list. ngl this is exactly the kind of detail you'll forget at 3am and then debug for an hour. 😭

and the special case, write it down: if size is == 0, the function returns 0. that's it. empty buffer energy. no characters, no drama, just a clean zero. 🫢

quick vibe check: size is the size including the trailing null space, and the return value excludes the trailing '\0'. those two facts are besties too, even though they sound like opposites. don't let them confuse you. ⭐

πŸ‘‘ SEE ALSO πŸ‘‘

this is the group chat this function rolls with, and honestly? stacked roster. πŸ†

the kernel file ./lib/vsprintf.c, then:

like, every single one of them. no cap, the whole friend group showed up. 🌈


and that's the page, bestie! πŸ’œ this little gem comes to you out of ./lib and it's dated October 2026, filed under scnprintf(9). go forth and format responsibly β€” count your null space, and slay. 🧚✨

πŸ“¦ where this page comes from