/*
* UCW Library -- Printf on Fastbuf Streams
*
- * (c) 2002 Martin Mares <mj@ucw.cz>
+ * (c) 2002--2005 Martin Mares <mj@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
{
va_copy(args2, args);
r = vsnprintf(buf, len, msg, args2);
+ va_end(args2);
if (r < 0)
len = 256;
else if (r < len)
buf = alloca(len);
va_copy(args2, args);
r = vsnprintf(buf, len, msg, args2);
+ va_end(args2);
if (r < 0)
len += len;
else if (r < len)
/*
* UCW Library -- Logging
*
- * (c) 1997--2004 Martin Mares <mj@ucw.cz>
+ * (c) 1997--2005 Martin Mares <mj@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
byte *buf, *p;
int buflen = 256;
int l, l0, r;
+ va_list args2;
if (log_switch_hook)
log_switch_hook(tm);
}
l0 = p - buf + 1;
r = buflen - l0;
- l = vsnprintf(p, r, msg, args);
+ va_copy(args2, args);
+ l = vsnprintf(p, r, msg, args2);
+ va_end(args2);
if (l < 0)
l = r;
else if (l < r)
ret = mp_alloc(p, 1);
free = p->last - p->free;
}
- int cnt = vsnprintf(ret, free, fmt, args);
+ va_list args2;
+ va_copy(args2, args);
+ int cnt = vsnprintf(ret, free, fmt, args2);
+ va_end(args2);
if (cnt < 0)
{
/* Our C library doesn't support C99 return value of vsnprintf, so we need to iterate */
{
len *= 2;
buf = alloca(len);
- cnt = vsnprintf(buf, len, fmt, args);
+ va_copy(args2, args);
+ cnt = vsnprintf(buf, len, fmt, args2);
+ va_end(args2);
}
while (cnt < 0);
ret = mp_alloc(p, cnt+1);
else
{
ret = mp_alloc(p, cnt+1);
- int cnt2 = vsnprintf(ret, cnt+1, fmt, args);
+ va_copy(args2, args);
+ int cnt2 = vsnprintf(ret, cnt+1, fmt, args2);
+ va_end(args2);
ASSERT(cnt2 == cnt);
}
return ret;
byte *arg;
while (arg = va_arg(cargs, byte *))
cnt++;
+ va_end(cargs);
char **argv = alloca(sizeof(byte *) * cnt);
argv[0] = cmd;
cnt = 1;
va_copy(cargs, args);
while (arg = va_arg(cargs, byte *))
argv[cnt++] = arg;
+ va_end(cargs);
argv[cnt] = NULL;
execv(cmd, argv);
byte echo[256];
byte *limit = buf + size - 4;
byte *p = buf;
byte *arg = cmd;
- va_list cargs;
- va_copy(cargs, args);
do
{
int l = strlen(arg);
memcpy(p, arg, l);
p += l;
}
- while (arg = va_arg(cargs, byte *));
+ while (arg = va_arg(args, byte *));
*p = 0;
}
uns
stk_printf_internal(char *fmt, ...)
{
- va_list args;
+ va_list args, args2;
va_start(args, fmt);
if (!stk_printf_buf)
{
}
for (;;)
{
- int l = vsnprintf(stk_printf_buf, stk_printf_len, fmt, args);
+ va_copy(args2, args);
+ int l = vsnprintf(stk_printf_buf, stk_printf_len, fmt, args2);
+ va_end(args2);
if (l < 0)
stk_printf_len *= 2;
else if (l < stk_printf_len)
- return l+1;
+ {
+ va_end(args);
+ return l+1;
+ }
else
stk_printf_len = MAX(stk_printf_len*2, l+1);
stk_printf_buf = xrealloc(stk_printf_buf, stk_printf_len);