common: fix varargs use in log{,v}print

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Kevin Shanahan 2012-12-17 13:02:41 +10:30
parent e100c9642b
commit f85b221da6
1 changed files with 14 additions and 5 deletions

View File

@ -21,9 +21,11 @@
* common/log.c * common/log.c
*/ */
#include <stdarg.h>
#include <stdio.h>
#include <common/log.h> #include <common/log.h>
#include <common/cmdlib.h> #include <common/cmdlib.h>
#include <stdio.h>
static FILE *logfile; static FILE *logfile;
static qboolean log_ok; static qboolean log_ok;
@ -48,20 +50,27 @@ logprint(const char *fmt, ...)
{ {
va_list args; va_list args;
va_start(args, fmt);
vprintf(fmt, args);
if (log_ok) { if (log_ok) {
va_start(args, fmt);
vfprintf(logfile, fmt, args); vfprintf(logfile, fmt, args);
va_end(args);
fflush(logfile); fflush(logfile);
} }
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
} }
void void
logvprint(const char *fmt, va_list args) logvprint(const char *fmt, va_list args)
{ {
vprintf(fmt, args); va_list log_args;
if (log_ok) { if (log_ok) {
vfprintf(logfile, fmt, args); va_copy(log_args, args);
vfprintf(logfile, fmt, log_args);
va_end(log_args);
fflush(logfile); fflush(logfile);
} }
vprintf(fmt, args);
} }