| 1 | #ifndef USTERR_H |
| 2 | #define USTERR_H |
| 3 | |
| 4 | #ifndef UST_COMPONENT |
| 5 | //#error UST_COMPONENT is undefined |
| 6 | #define UST_COMPONENT libust |
| 7 | #endif |
| 8 | |
| 9 | /* To stringify the expansion of a define */ |
| 10 | #define XSTR(d) STR(d) |
| 11 | #define STR(s) #s |
| 12 | |
| 13 | #define UST_STR_COMPONENT XSTR(UST_COMPONENT) |
| 14 | |
| 15 | #define DEBUG |
| 16 | #ifdef DEBUG |
| 17 | # define DBG(fmt, args...) do { fprintf(stderr, UST_STR_COMPONENT ": " fmt "(" __FILE__ ":" XSTR(__LINE__) ")\n", ## args); fflush(stderr); } while(0) |
| 18 | #else |
| 19 | # define DBG(fmt, args...) do {} while(0) |
| 20 | #endif |
| 21 | #define WARN(fmt, args...) fprintf(stderr, UST_STR_COMPONENT ": Warning: " fmt "\n", ## args); fflush(stderr) |
| 22 | #define ERR(fmt, args...) fprintf(stderr, UST_STR_COMPONENT ": Error: " fmt "\n", ## args); fflush(stderr) |
| 23 | #define BUG(fmt, args...) fprintf(stderr, UST_STR_COMPONENT ": BUG: " fmt "\n", ## args); fflush(stderr) |
| 24 | #define PERROR(call) perror("ust: ERROR: " call) |
| 25 | |
| 26 | #define BUG_ON(condition) do { if (unlikely(condition)) ERR("condition not respected (BUG)"); } while(0) |
| 27 | #define WARN_ON(condition) do { if (unlikely(condition)) WARN("condition not respected on line %s:%d", __FILE__, __LINE__); } while(0) |
| 28 | |
| 29 | #endif /* USTERR_H */ |