Limited-length variant of vsprintf() for Q3VM.


Original bg_lib.c lacks vsnprintf() (and thus a snprintf()). This patch also includes the hexadecimal printing patch.

An exchange on IRC prompted me to make a vsnprintf() targeted for Q3VM.


snprintf(char *buf, size_t size, const char *fmt, ...);
vsnprintf(char *buf, size_t size, const char *fmt, va_list argptr);

The return value is the number of characters needed in buf (C99 semantics). This either reflects the number of characters actually written (if enough space was available) or the total number of charaters needed to completely write out the formatted string (if not enough space).


No additional functional limitations added to those already existent in bg_lib.c's vsprintf().

Maybe this should be called Q_vsnprintf() instead?

Make a Q_snprintf() or a Com_snprintf() as well?

Programming Notes

Functions AddInt(), AddFloat(), and AddString() are modified to accept an extra parameter, based on `size' passed to vsnprintf().

This vsnprintf() is basically just a modified variant of the extant vsprintf(). The original vsprintf() is still in there, #ifdef'd out, but won't work, as the supporting routines AddInt(), AddFloat(), and AddString() have been modified to take an additional parameter.

The new vsprintf() is just a wrapper around vsnprintf() with `size' of INT_MAX.

There's probably room for optimization, but oh well.

-- PhaethonH (PhaethonH@gmail.com)