> Note that in Unix, vsnprintf() returns the TOTAL number of chars
> needed (add 1 for the null).

This is not correct.  The buffer size (that you pass in) is the total
number of bytes available (and the most the function shall use,
including the terminator); but the *return* is the strlen() that would
have resulted had the buffer been big enough.  If this is the buffer
size you passed in, the output has been truncated, in order to fit in
the terminator, by one byte; but the return doesn't include the
terminator.

> If the output would overflow the buffer, then you would get a return
> value larger than the specified buffer size.

Yes, and you need to add one to the return value to get the buffer size
you need for the subsequent call that'll get the job done properly.  The
function hasn't added one for the terminator: you need to do that.

> In Windoze, vsnprintf() will return -1 if the buffer would be
> overflowed,

This is quite usual amongst iron-age implementations of libc.

        Eddy.

_______________________________________________
Bug-make mailing list
Bug-make@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-make

Reply via email to