-
Notifications
You must be signed in to change notification settings - Fork 2
/
debug.h
52 lines (40 loc) · 1.44 KB
/
debug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* `debug.h' - debug.c
*
* copyright (c) 2014 joseph werle <joseph.werle@gmail.com>
*/
#ifndef DEBUG_H
#define DEBUG_H 1
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
/**
* Debug function type
*/
typedef void (* debug_t) (const char *, ...);
/**
* Initialize a debug function
*/
#define debug_init(name) \
void _debug_ ## name (const char *fmt, ...) { \
if (!debug_enabled(#name)) { return; } \
char *buf = NULL; \
va_list args; \
va_start(args, fmt); \
if (-1 != vasprintf(&buf, fmt, args)) { \
printf(#name " - %s\n", buf); \
} \
va_end(args); \
free(buf); \
} \
/**
* Return a named debug function
*/
#define debug_get(name) (debug_t) ( _debug_ ## name)
/**
* Returns `1' if a function is enabled
* else `0'
*/
int
debug_enabled (const char *);
#endif