dect
/
libdect
Archived
13
0
Fork 0

debug: allow to disable debugging code

Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
Patrick McHardy 2010-02-18 03:56:15 +01:00
parent 8468ade3a3
commit 0d301955cf
3 changed files with 16 additions and 4 deletions

View File

@ -18,8 +18,16 @@
#define __aligned(x) __attribute__((aligned(x)))
#define __packed __attribute__((packed))
extern void dect_debug(const char *fmt, ...) __fmtstring(1, 2);
extern void dect_hexdump(const char *prefix, const uint8_t *buf, size_t size);
extern void __dect_debug(const char *fmt, ...) __fmtstring(1, 2);
extern void __dect_hexdump(const char *prefix, const uint8_t *buf, size_t size);
#ifdef DEBUG
#define dect_debug(fmt, ...) __dect_debug(fmt, ## __VA_ARGS__)
#define dect_hexdump(pfx, buf, size) __dect_hexdump(pfx, buf, size)
#else
#define dect_debug(fmt, ...) ({ if (0) __dect_debug(fmt, ## __VA_ARGS__); })
#define dect_hexdump(pfx, buf, size) ({ if (0) __dect_hexdump(pfx, buf, size); })
#endif
struct dect_trans_tbl {
uint64_t val;

View File

@ -25,7 +25,8 @@ void dect_set_debug_hook(int (*fn)(const char *fmt, va_list ap))
debug_hook = fn;
}
void __fmtstring(1, 2) dect_debug(const char *fmt, ...)
#ifdef DEBUG
void __fmtstring(1, 2) __dect_debug(const char *fmt, ...)
{
va_list ap;
@ -36,6 +37,7 @@ void __fmtstring(1, 2) dect_debug(const char *fmt, ...)
vprintf(fmt, ap);
va_end(ap);
}
#endif
struct dect_handle *dect_alloc_handle(struct dect_ops *ops)
{

View File

@ -28,7 +28,8 @@
#define BLOCKSIZE 16
void dect_hexdump(const char *prefix, const uint8_t *buf, size_t size)
#ifdef DEBUG
void __dect_hexdump(const char *prefix, const uint8_t *buf, size_t size)
{
unsigned int i, off;
char hbuf[3 * BLOCKSIZE + 1], abuf[BLOCKSIZE + 1];
@ -93,6 +94,7 @@ const char *__dect_val2str(const struct dect_trans_tbl *tbl, unsigned int nelem,
snprintf(buf, size, "unknown (%" PRIx64 ")", val);
return buf;
}
#endif
void *dect_malloc(const struct dect_handle *dh, size_t size)
{