dprintf: add the ability to log to stdio
authorH. Peter Anvin <hpa@zytor.com>
Tue, 21 Jun 2011 04:19:17 +0000 (21:19 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Tue, 21 Jun 2011 04:19:17 +0000 (21:19 -0700)
Add the ability to redirect dprintf to stdio when there is no other
choice.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
com32/include/dprintf.h
com32/lib/dprintf.c
com32/lib/vdprintf.c

index 30a21ad..4bdf7a7 100644 (file)
@@ -7,15 +7,29 @@
 
 #ifdef DEBUG
 
-#include <stdio.h>
+# include <stdio.h>
 
+# ifdef DEBUG_STDIO
+#  define dprintf  printf
+#  define vdprintf vprintf
+# else
 void dprintf(const char *, ...);
 void vdprintf(const char *, va_list);
+# endif
+
+# if DEBUG >= 2
+/* Really verbose debugging... */
+#  define dprintf2  dprintf
+#  define vdprintf2 vdprintf
+# else
+#  define dprintf2(fmt, ...)   ((void)(0))
+#  define vdprintf2(fmt, ap)   ((void)(0))
+# endif
 
 #else
 
-#define dprintf(fmt, ...)      ((void)(0))
-#define vdprintf(fmt, ap)      ((void)(0))
+# define dprintf(fmt, ...)     ((void)(0))
+# define vdprintf(fmt, ap)     ((void)(0))
 
 #endif /* DEBUG */
 
index 900c0a4..aad1174 100644 (file)
@@ -9,6 +9,7 @@
 #define DEBUG 1
 #include <dprintf.h>
 
+#ifndef dprintf
 void dprintf(const char *format, ...)
 {
     va_list ap;
@@ -17,3 +18,4 @@ void dprintf(const char *format, ...)
     vdprintf(format, ap);
     va_end(ap);
 }
+#endif
index d74f278..c1f90a6 100644 (file)
@@ -14,6 +14,8 @@
 #define DEBUG 1
 #include <dprintf.h>
 
+#ifndef vdprintf
+
 #define BUFFER_SIZE    4096
 
 enum serial_port_regs {
@@ -114,3 +116,5 @@ void vdprintf(const char *format, va_list ap)
     while (rv--)
        debug_putc(*p++);
 }
+
+#endif /* vdprintf */