summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2016-03-27 18:48:03 +0200
committerDavid Tardon <dtardon@redhat.com>2016-03-27 18:48:03 +0200
commit34d8b1ce7188e22ce73d589ef360aa72913a9b09 (patch)
treecee4705cc59fe450b66bdb231ccbe555b3445a62
parentf0761d9603527d5a97a84b94dc772a48a3cc5ef3 (diff)
print debug msgs to stderr
-rw-r--r--src/lib/libsw602_utils.cpp17
-rw-r--r--src/lib/libsw602_utils.h19
2 files changed, 29 insertions, 7 deletions
diff --git a/src/lib/libsw602_utils.cpp b/src/lib/libsw602_utils.cpp
index 78f264c..1ae5dbf 100644
--- a/src/lib/libsw602_utils.cpp
+++ b/src/lib/libsw602_utils.cpp
@@ -7,10 +7,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#include <cstdio>
-
#include "libsw602_utils.h"
+#include <cstdarg>
+#ifdef DEBUG
+#include <cstdio>
+#endif
+
namespace libsw602
{
@@ -125,6 +128,16 @@ void skip(librevenge::RVNGInputStream &input, unsigned long numBytes)
}
}
+#ifdef DEBUG
+void debugPrint(const char *const format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ std::vfprintf(stderr, format, args);
+ va_end(args);
+}
+#endif
+
}
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/lib/libsw602_utils.h b/src/lib/libsw602_utils.h
index d8cbda2..e49c4c6 100644
--- a/src/lib/libsw602_utils.h
+++ b/src/lib/libsw602_utils.h
@@ -10,18 +10,23 @@
#ifndef INCLUDED_LIBSW602_UTILS_H
#define INCLUDED_LIBSW602_UTILS_H
-#ifdef DEBUG
-#include <cstdio>
-#endif
-
#include <boost/cstdint.hpp>
#include <librevenge-stream/librevenge-stream.h>
#include <librevenge/librevenge.h>
+namespace libsw602
+{
+}
+
// do nothing with debug messages in a release compile
#ifdef DEBUG
-#define SW602_DEBUG_MSG(M) std::printf M
+#if defined(__clang__) || defined(__GNUC__)
+# define SW602_ATTRIBUTE_PRINTF(fmt, arg) __attribute__((__format__(__printf__, fmt, arg)))
+#else
+# define SW602_ATTRIBUTE_PRINTF(fmt, arg)
+#endif
+#define SW602_DEBUG_MSG(M) libsw602::debugPrint M
#define SW602_DEBUG(M) M
#else
#define SW602_DEBUG_MSG(M)
@@ -58,6 +63,10 @@ const unsigned char *readNBytes(librevenge::RVNGInputStream &input, unsigned lon
void skip(librevenge::RVNGInputStream &input, unsigned long numBytes);
+#ifdef DEBUG
+void debugPrint(const char *format, ...) SW602_ATTRIBUTE_PRINTF(1, 2);
+#endif
+
class EndOfStreamException
{
};