GenSVM
All Classes Files Functions Variables Enumerations Enumerator Macros Pages
dbg.h
Go to the documentation of this file.
1 
13 #ifndef __dbg_h__
14 #define __dbg_h__
15 
16 #include <stdio.h>
17 #include <errno.h>
18 #include <string.h>
19 
20 #ifdef NDEBUG
21 
24  #define debug(M, ...)
25 #else
26 
29  #define debug(M, ...) fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, \
30  __LINE__, ##__VA_ARGS__)
31 #endif
32 
36 #define clean_errno() (errno == 0 ? "None" : strerror(errno))
37 
41 #define log_err(M, ...) fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", \
42  __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
43 
47 #define log_warn(M, ...) fprintf(stderr, "[WARN] (%s:%d: errno: %s) " M "\n", \
48  __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
49 
53 #define log_info(M, ...) fprintf(stderr, "[INFO] (%s:%d) " M "\n", \
54  __FILE__, __LINE__, ##__VA_ARGS__)
55 
59 #define check(A, M, ...) if(!(A)) { log_err(M, ##__VA_ARGS__); errno=0; \
60  goto error; }
61 
65 #define sentinel(M, ...) { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
66 
70 #define check_mem(A) check((A), "Out of memory.");
71 
75 #define check_debug(A, M, ...) if (!(A)) { debug(M, ##__VA_ARGS__); errno=0; \
76  goto error; }
77 
78 #endif