summaryrefslogtreecommitdiff
path: root/Xtransint.h
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2011-09-23 22:35:03 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2011-10-01 08:55:11 -0700
commitb1b69ce8e8e4fe0f190c8bd85b537309e71055c8 (patch)
treea6480c97e61c66ea6b4dcda42345d3bf9c6209a6 /Xtransint.h
parentcbdb434033da1725a69014cc6e4d89c691a6fd95 (diff)
downloadxorg-lib-libxtrans-b1b69ce8e8e4fe0f190c8bd85b537309e71055c8.tar.gz
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 <alan.coopersmith@oracle.com> Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
Diffstat (limited to 'Xtransint.h')
-rw-r--r--Xtransint.h100
1 files changed, 53 insertions, 47 deletions
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 <stdarg.h>
+
+/*
+ * 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 */