aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxc/xc_private.h
diff options
context:
space:
mode:
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2006-06-07 14:07:36 +0100
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2006-06-07 14:07:36 +0100
commit2928514138945c3ed7e5d34ca726d2904476852c (patch)
treef7485ca1a67cd730f61783b40872761ff5386aa6 /tools/libxc/xc_private.h
parente56ed2dc521d9eccbcfb4db7de22ab621705864f (diff)
downloadxen-2928514138945c3ed7e5d34ca726d2904476852c.tar.gz
xen-2928514138945c3ed7e5d34ca726d2904476852c.tar.bz2
xen-2928514138945c3ed7e5d34ca726d2904476852c.zip
[LIBXC] Convert all printf/fprintf uses to use a macro instead.
Thus all can be disabled at compile time. It would be easy to make enabling/disabling a run-time option too. Signed-off-by: Keir Fraser <keir@xensource.com>
Diffstat (limited to 'tools/libxc/xc_private.h')
-rw-r--r--tools/libxc/xc_private.h51
1 files changed, 38 insertions, 13 deletions
diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h
index f0ee3cc0ed..6e1b262375 100644
--- a/tools/libxc/xc_private.h
+++ b/tools/libxc/xc_private.h
@@ -28,27 +28,52 @@
#define DECLARE_DOM0_OP dom0_op_t op
#endif
-
#define PAGE_SHIFT XC_PAGE_SHIFT
#define PAGE_SIZE (1UL << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE-1))
-#define ERROR(_m, _a...) \
+#define DEBUG 1
+#define INFO 1
+#define PROGRESS 0
+
+#if INFO
+#define IPRINTF(_f, _a...) printf(_f , ## _a)
+#else
+#define IPRINTF(_f, _a...) ((void)0)
+#endif
+
+#if DEBUG
+#define DPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
+#else
+#define DPRINTF(_f, _a...) ((void)0)
+#endif
+
+#if PROGRESS
+#define PPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
+#else
+#define PPRINTF(_f, _a...)
+#endif
+
+#define ERR(_f, _a...) do { \
+ DPRINTF(_f ": %d\n" , ## _a, errno); \
+ fflush(stderr); } \
+while (0)
+
+#define ERROR(_m, _a...) \
+do { \
+ int __saved_errno = errno; \
+ DPRINTF("ERROR: " _m "\n" , ## _a ); \
+ errno = __saved_errno; \
+} while (0)
+
+#define PERROR(_m, _a...) \
do { \
int __saved_errno = errno; \
- fprintf(stderr, "ERROR: " _m "\n" , ## _a ); \
+ DPRINTF("ERROR: " _m " (%d = %s)\n" , ## _a , \
+ __saved_errno, strerror(__saved_errno)); \
errno = __saved_errno; \
} while (0)
-
-#define PERROR(_m, _a...) \
-do { \
- int __saved_errno = errno; \
- fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
- __saved_errno, strerror(__saved_errno)); \
- errno = __saved_errno; \
-} while (0)
-
static inline void safe_munlock(const void *addr, size_t len)
{
int saved_errno = errno;
@@ -88,7 +113,7 @@ static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
{
if ( errno == EACCES )
- fprintf(stderr, "Dom0 operation failed -- need to"
+ DPRINTF("Dom0 operation failed -- need to"
" rebuild the user-space tool set?\n");
}