Yes, it's a GNU extension, but it's also supported by various BSDs [1][2][3], and yes, Musl has it too. It's present in pretty much any sane C library.
[1] https://man.openbsd.org/man3/printf.3
[2] https://man.netbsd.org/vasprintf.3
[3] https://man.freebsd.org/cgi/man.cgi?query=vasprintf&sektion=...
https://github.com/RhysU/snprintf_realloc/blob/master/snprin...
Worth critically reviewing before using. It's been a while.
hdjrudni•2d ago
> I have size_with_nul because snprintf man pages say
> The functions snprintf() and vsnprintf() write at most size bytes (including the terminating null byte (‘\0’)) to str.
If 'size' includes the null byte, why do we have to add 1?
king_geedorah•2d ago
The initial call with size 0 tells you the necessary length of the buffer for the string you want, but does not include the null byte.
orbisvicis•58m ago
1. https://man7.org/linux/man-pages/man3/fprintf.3p.html
chrsw•11m ago