10 #define FAILIF(cond, msg...) do { \
11 if (unlikely(cond)) { \
12 fprintf(stderr, "%s(%d): ", __FILE__, __LINE__); \
13 fprintf(stderr, ##msg); \
19 #define ASSERT(x) do { \
20 if (unlikely(!(x))) { \
22 "ASSERTION FAILURE %s:%d: [%s]\n", \
23 __FILE__, __LINE__, #x); \
30 #define FAILIF(cond, msg...) do { \
31 if (unlikely(cond)) { \
32 fprintf(stderr, ##msg); \
38 #define ASSERT(x) do { } while(0)
42 #define FAILIF_LIBELF(cond, function) \
43 FAILIF(cond, "%s(): %s\n", #function, elf_errmsg(elf_errno()));
45 static inline void *MALLOC(unsigned int size) {
46 void *m = malloc(size);
47 FAILIF(NULL == m, "malloc(%d) failed!\n", size);
51 static inline void *CALLOC(unsigned int num_entries, unsigned int entry_size) {
52 void *m = calloc(num_entries, entry_size);
53 FAILIF(NULL == m, "calloc(%d, %d) failed!\n", num_entries, entry_size);
57 static inline void *REALLOC(void *ptr, unsigned int size) {
58 void *m = realloc(ptr, size);
59 FAILIF(NULL == m, "realloc(%p, %d) failed!\n", ptr, size);
63 static inline void FREE(void *ptr) {
67 static inline void FREEIF(void *ptr) {
71 #define PRINT(x...) do { \
72 extern int quiet_flag; \
73 if(likely(!quiet_flag)) \
74 fprintf(stdout, ##x); \
77 #define ERROR(x...) fprintf(stderr, ##x)
79 #define INFO(x...) do { \
80 extern int verbose_flag; \
81 if(unlikely(verbose_flag)) \
82 fprintf(stdout, ##x); \
85 /* Prints a hex and ASCII dump of the selected buffer to the selected stream. */
86 int dump_hex_buffer(FILE *s, void *b, size_t l, size_t elsize);