mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-05-31 16:51:08 +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 (const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
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)
|
if (!string[0]) {
|
||||||
string = dstring_new ();
|
for (size_t i = 0; i < NUM_STRINGS; i++) {
|
||||||
|
string[i] = dstring_new ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dstr = string[str_index++ % NUM_STRINGS];
|
||||||
|
|
||||||
va_start (args, fmt);
|
va_start (args, fmt);
|
||||||
dvsprintf (string, fmt, args);
|
dvsprintf (dstr, fmt, args);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
|
|
||||||
return string->str;
|
return dstr->str;
|
||||||
}
|
}
|
||||||
|
|
||||||
VISIBLE char *
|
VISIBLE char *
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue