vsnprintf(9)
π 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 ava_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:
simple_strtoull(9)simple_strtoul(9)simple_strtol(9)simple_strtoll(9)vscnprintf(9)snprintf(9)scnprintf(9)vsprintf(9)sprintf(9)vbin_printf(9)bstr_printf(9)vsscanf(9)sscanf(9)
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
- 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