From b1b69ce8e8e4fe0f190c8bd85b537309e71055c8 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 23 Sep 2011 22:35:03 -0700 Subject: Convert PRMSG macro to prmsg inline function Allows using varargs to have the correct number of arguments passed to get rid of the many gcc warnings about variable printf format strings, and to reduce the duplication from having 5 implementations of the PRMSG macro depending on the debug options defined & output method used. Signed-off-by: Alan Coopersmith Reviewed-by: Jeremy Huddleston --- Xtransint.h | 100 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 53 insertions(+), 47 deletions(-) (limited to 'Xtransint.h') diff --git a/Xtransint.h b/Xtransint.h index 47d98ba..bfd79d6 100644 --- a/Xtransint.h +++ b/Xtransint.h @@ -374,55 +374,61 @@ static int trans_mkdir ( * Some XTRANSDEBUG stuff */ -#if defined(XTRANSDEBUG) -/* add hack to the format string to avoid warnings about extra arguments - * to fprintf. +#ifdef XTRANSDEBUG +#include + +/* + * The X server provides ErrorF() & VErrorF(), for other software that uses + * xtrans, we provide our own simple versions. */ -#ifdef XTRANSDEBUGTIMESTAMP -#if defined(XSERV_t) && defined(TRANS_SERVER) -/* Use ErrorF() for the X server */ -#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ - int hack= 0, saveerrno=errno; \ - struct timeval tp;\ - gettimeofday(&tp,0); \ - ErrorF("%s",__xtransname); \ - ErrorF(x+hack,a,b,c); \ - ErrorF("timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \ - errno=saveerrno; \ - } else ((void)0) -#else -#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ - int hack= 0, saveerrno=errno; \ - struct timeval tp;\ - gettimeofday(&tp,0); \ - fprintf(stderr, "%s", __xtransname); fflush(stderr); \ - fprintf(stderr, x+hack,a,b,c); fflush(stderr); \ - fprintf(stderr, "timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \ - fflush(stderr); \ - errno=saveerrno; \ - } else ((void)0) -#endif /* XSERV_t && TRANS_SERVER */ -#else /* XTRANSDEBUGTIMESTAMP */ -#if defined(XSERV_t) && defined(TRANS_SERVER) -/* Use ErrorF() for the X server */ -#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ - int hack= 0, saveerrno=errno; \ - ErrorF("%s",__xtransname); \ - ErrorF(x+hack,a,b,c); \ - errno=saveerrno; \ - } else ((void)0) -#else -#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ - int hack= 0, saveerrno=errno; \ - fprintf(stderr, "%s", __xtransname); fflush(stderr); \ - fprintf(stderr, x+hack,a,b,c); fflush(stderr); \ - errno=saveerrno; \ - } else ((void)0) -#endif /* XSERV_t && TRANS_SERVER */ -#endif /* XTRANSDEBUGTIMESTAMP */ -#else -#define PRMSG(lvl,x,a,b,c) ((void)0) +# if defined(XSERV_t) && defined(TRANS_SERVER) +# include "os.h" +# else +static inline void _X_ATTRIBUTE_PRINTF(1, 0) +VErrorF(const char *f, va_list args) +{ + vfprintf(stderr, f, args); + fflush(stderr); +} + +static inline void _X_ATTRIBUTE_PRINTF(1, 2) +ErrorF(const char *f, ...) +{ + va_list args; + + va_start(args, f); + VErrorF(f, args); + va_end(args); +} +# endif /* xserver */ +#endif /* XTRANSDEBUG */ + +static inline void _X_ATTRIBUTE_PRINTF(2, 3) +prmsg(int lvl, const char *f, ...) +{ +#ifdef XTRANSDEBUG + va_list args; + + va_start(args, f); + if (lvl <= XTRANSDEBUG) { + int saveerrno = errno; + + ErrorF("%s", __xtransname); + VErrorF(f, args); + +# ifdef XTRANSDEBUGTIMESTAMP + { + struct timeval tp; + gettimeofday(&tp, 0); + ErrorF("timestamp (ms): %d\n", + tp.tv_sec * 1000 + tp.tv_usec / 1000); + } +# endif + errno = saveerrno; + } + va_end(args); #endif /* XTRANSDEBUG */ +} #endif /* XTRANS_TRANSPORT_C */ -- cgit v1.2.3