mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
[util] Make va slight robust against chained use
va now cycles through a set of four dstrings rather than using just the one. This allows for some simple chaining of va usage.
This commit is contained in:
parent
c5cbe83f71
commit
0cbe438ac1
1 changed files with 12 additions and 5 deletions
|
@ -51,16 +51,23 @@ VISIBLE char *
|
|||
va (const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
static dstring_t *string;
|
||||
static dstring_t *string[4];
|
||||
#define NUM_STRINGS (sizeof (string) / sizeof (string[0]))
|
||||
static int str_index;
|
||||
dstring_t *dstr;
|
||||
|
||||
if (!string)
|
||||
string = dstring_new ();
|
||||
if (!string[0]) {
|
||||
for (size_t i = 0; i < NUM_STRINGS; i++) {
|
||||
string[i] = dstring_new ();
|
||||
}
|
||||
}
|
||||
dstr = string[str_index++ % NUM_STRINGS];
|
||||
|
||||
va_start (args, fmt);
|
||||
dvsprintf (string, fmt, args);
|
||||
dvsprintf (dstr, fmt, args);
|
||||
va_end (args);
|
||||
|
||||
return string->str;
|
||||
return dstr->str;
|
||||
}
|
||||
|
||||
VISIBLE char *
|
||||
|
|
Loading…
Reference in a new issue