vsnprintf(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– vsnprintf(9) β€” Kernel API Manual πŸ’–

okay so bestie, listen, this is <pink>vsnprintf(9)</pink> from the Kernel API Manual and it's literally the vibes of formatting a string into a buffer, kernel edition. Buckle up. πŸŽ€


✨ NAME ✨

vsnprintf β€” Format a string and place it in a buffer 🌸

That's it. That's the whole pitch. It formats, it places, it slays.


πŸ¦‹ SYNOPSIS πŸ¦‹

int vsnprintf (char *buf , size_t size , const char *fmt_str , va_list
args );

Copy that exactly, no cap. πŸ‘‘


πŸ“ ARGUMENTS πŸ“

  • buf β€” the buffer where the result goes. It's giving "here's where the magic lands" energy. πŸ’…
  • size β€” the size of that buffer, and yes it includes the trailing null space, so don't come for her, she counts the terminator too. πŸ™ˆ
  • fmt_str β€” the format string you're working with. The blueprint. The main character. ⭐
  • args β€” the arguments for the format string, bundled up in a va_list. πŸ’œ

πŸ”₯ DESCRIPTION πŸ”₯

So this function generally follows C99 vsnprintf, but she has some extensions and a couple of limitations, and you need to know them:

  • `n` is unsupported. Periodt. It's just not happening. πŸ’€
  • `p*` is handled by pointer. iykyk. 🫢

See pointer or Documentation/core-api/printk-formats.rst for a way more extensive description. Go read it, it ate. 🌈

Please update the documentation in both places when making changes ✨ β€” like fr fr, both places, don't leave one of them in the group chat without the update. 😭

Now the return value, because this part is lowkey the whole plot twist: the return value is the number of characters which would be generated for the given input, excluding the trailing number of characters written into buf as return value (not including the trailing ' ') β€” and if that's the flavor you want, use vscnprintf. If the return is greater than or equal to size, the resulting string is truncated. That's the truncation moment, bestie, it's giving cliffhanger. πŸ’€πŸŒΈ

And if you're not already dealing with a va_list, consider using snprintf. Save yourself the trouble. 🧚


πŸ‘‘ SEE ALSO πŸ‘‘

Kernel file ./lib/vsprintf.c, plus the whole friend group:

All iconic, all linked, all worth a read. πŸ’–


and that's the page!! this lil bundle of joy lives in ./lib, dated October 2026, and answers to the name vsnprintf(9). mwah πŸ’‹ πŸŽ€βœ¨

πŸ“¦ where this page comes from