errors.h (670B)
1 2 #ifndef CHIBIPUB_ERRORS 3 #define CHIBIPUB_ERRORS 4 5 #include <stdarg.h> 6 7 #define note_error(p, msg, ...) note_error_(p, "%s: " msg "\n", __FUNCTION__, ##__VA_ARGS__); 8 9 struct errors { 10 int record; 11 int depth; 12 }; 13 14 static inline void copy_errors(struct errors *src, struct errors *dst) 15 { 16 dst->record = src->record; 17 } 18 19 static inline void init_errors(struct errors *errs) 20 { 21 errs->record = 1; 22 errs->depth = 0; 23 } 24 25 static inline void note_error_(struct errors *errs, const char *fmt, ...) 26 { 27 if (!errs->record) { 28 return; 29 } 30 31 va_list ap; 32 va_start(ap, fmt); 33 fprintf(stderr, "[%d] ", errs->depth++); 34 vfprintf(stderr, fmt, ap); 35 va_end(ap); 36 } 37 38 39 #endif /* CHIBIPUB_ERRORS */