libDXF 0.0.1
A library with DXF related functions written in C.

dbg.h

Go to the documentation of this file.
00001 
00037 #ifndef LIBDXF_SRC_DBG_H
00038 #define LIBDXF_SRC_DBG_H
00039 
00040 
00041 #include <stdio.h>
00042 #include <errno.h>
00043 #include <string.h>
00044 
00045 
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #endif
00049 
00050 
00051 #ifdef NDEBUG
00052 #define debug(M, ...)
00053 #else
00054 #define debug(M, ...) fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
00055 #endif
00056 
00057 
00062 #define clean_errno() (errno == 0 ? "None" : strerror(errno))
00063 
00064 
00069 #define log_err(M, ...) fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
00070 
00075 #define log_warn(M, ...) fprintf(stderr, "[WARNING] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
00076 
00081 #define log_info(M, ...) fprintf(stderr, "[INFO] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
00082 
00083 
00089 #define check(A, M, ...) if(!(A)) { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
00090 
00098 #define sentinel(M, ...)  { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
00099 
00100 
00105 #define check_mem(A) check((A), "Out of memory.")
00106 
00107 
00116 #define check_debug(A, M, ...) if(!(A)) { debug(M, ##__VA_ARGS__); errno=0; goto error; }
00117 
00118 
00119 #ifdef __cplusplus
00120 }
00121 #endif
00122 
00123 
00124 #endif /* LIBDXF_SRC_DBG_H */
00125 
00126 
00127 /* EOF */