common.c (va): made va() to cycle between four static buffers so that we

can call it one after another. will be needed later.
(get_va_buffer): new helper for va().


git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@92 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2010-03-01 10:28:12 +00:00
parent 90204323c7
commit d100f32fc0

View file

@ -1263,21 +1263,34 @@ void COM_Init (char *basedir)
============
va
does a varargs printf into a temp buffer, so I don't need to have
varargs versions of all text functions.
does a varargs printf into a temp buffer. cycles between
4 different static buffers. the number of buffers cycled
is defined in VA_NUM_BUFFS.
FIXME: make this buffer size safe someday
============
*/
#define VA_NUM_BUFFS 4
#define VA_BUFFERLEN 1024
static char *get_va_buffer(void)
{
static char va_buffers[VA_NUM_BUFFS][VA_BUFFERLEN];
static int buffer_idx = 0;
buffer_idx = (buffer_idx + 1) & (VA_NUM_BUFFS - 1);
return va_buffers[buffer_idx];
}
char *va(char *format, ...)
{
va_list argptr;
static char string[1024];
char *va_buf;
va_buf = get_va_buffer ();
va_start (argptr, format);
vsprintf (string, format, argptr);
vsprintf (va_buf, format, argptr);
va_end (argptr);
return string;
return va_buf;
}