From a6fe6a30d31cd41b74a41bed73219c404c3210df Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Thu, 23 Jun 2011 18:47:58 +0200 Subject: [PATCH] fixed building for --without-debug make coap_log re-definable --- debug.c | 54 +++++++++++++++++++++++++++--------------------------- debug.h | 6 +++++- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/debug.c b/debug.c index 254f82c2..39de6837 100644 --- a/debug.c +++ b/debug.c @@ -41,8 +41,6 @@ static char *loglevels[] = { "EMRG", "ALRT", "CRIT", "WARN", "NOTE", "INFO", "DEBG" }; -#ifndef NDEBUG - #ifdef HAVE_TIME_H static inline size_t @@ -64,6 +62,8 @@ print_timestamp(char *s, size_t len, coap_tick_t t) { #endif /* HAVE_TIME_H */ +#ifndef NDEBUG + /** * A length-safe strlen() fake. * @@ -80,31 +80,6 @@ strnlen(unsigned char *s, size_t maxlen) { return n; } -void -coap_log(coap_log_t level, char *format, ...) { - char timebuf[32]; - coap_tick_t now; - va_list ap; - FILE *log_fd; - - if (maxlog < level) - return; - - log_fd = level <= LOG_CRIT ? COAP_ERR_FD : COAP_DEBUG_FD; - - coap_ticks(&now); - if (print_timestamp(timebuf,sizeof(timebuf), now)) - fprintf(log_fd, "%s ", timebuf); - - if (level <= LOG_DEBUG) - fprintf(log_fd, "%s ", loglevels[level]); - - va_start(ap, format); - vfprintf(log_fd, format, ap); - va_end(ap); - fflush(stdout); -} - unsigned int print_readable( const unsigned char *data, unsigned int len, unsigned char *result, unsigned int buflen, int encode_always ) { @@ -222,3 +197,28 @@ coap_show_pdu(const coap_pdu_t *pdu) { } #endif /* NDEBUG */ + +void +coap_log_impl(coap_log_t level, char *format, ...) { + char timebuf[32]; + coap_tick_t now; + va_list ap; + FILE *log_fd; + + if (maxlog < level) + return; + + log_fd = level <= LOG_CRIT ? COAP_ERR_FD : COAP_DEBUG_FD; + + coap_ticks(&now); + if (print_timestamp(timebuf,sizeof(timebuf), now)) + fprintf(log_fd, "%s ", timebuf); + + if (level <= LOG_DEBUG) + fprintf(log_fd, "%s ", loglevels[level]); + + va_start(ap, format); + vfprintf(log_fd, format, ap); + va_end(ap); + fflush(stdout); +} diff --git a/debug.h b/debug.h index 8fa85f96..d5f230ae 100644 --- a/debug.h +++ b/debug.h @@ -34,7 +34,11 @@ void coap_set_log_level(coap_log_t level); * text is output only when @p level is below or equal to the log * level that set by coap_set_log_level(). */ -void coap_log(coap_log_t level, char *format, ...); +void coap_log_impl(coap_log_t level, char *format, ...); + +#ifndef coap_log +#define coap_log(...) coap_log_impl(__VA_ARGS__) +#endif #ifndef NDEBUG