1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <errno.h> #include <string.h>
#ifdef DEBUG #define DBG_PRINT(fmt, ...) \ fprintf(stderr, "[DEBUG] %s:%d:%s(): " fmt "\n", \ __FILE__, __LINE__, __func__, ##__VA_ARGS__) #define DBG_ENTER() \ fprintf(stderr, "[ENTER] %s:%d:%s()\n", \ __FILE__, __LINE__, __func__) #define DBG_EXIT() \ fprintf(stderr, "[EXIT] %s:%d:%s()\n", \ __FILE__, __LINE__, __func__) #else #define DBG_PRINT(fmt, ...) #define DBG_ENTER() #define DBG_EXIT() #endif
#define ASSERT_NOT_NULL(ptr) \ do { \ if ((ptr) == NULL) { \ fprintf(stderr, "Assertion failed: %s is NULL at %s:%d\n", \ #ptr, __FILE__, __LINE__); \ abort(); \ } \ } while(0)
#define ASSERT_RANGE(val, min, max) \ do { \ if ((val) < (min) || (val) > (max)) { \ fprintf(stderr, "Assertion failed: %s (%d) not in range [%d, %d] at %s:%d\n", \ #val, (val), (min), (max), __FILE__, __LINE__); \ abort(); \ } \ } while(0)
#define CHECK_ERRNO(expr) \ do { \ if ((expr) == -1) { \ fprintf(stderr, "Error at %s:%d: %s\n", \ __FILE__, __LINE__, strerror(errno)); \ exit(EXIT_FAILURE); \ } \ } while(0)
#define CHECK_NULL(ptr) \ do { \ if ((ptr) == NULL) { \ fprintf(stderr, "Null pointer at %s:%d\n", \ __FILE__, __LINE__); \ exit(EXIT_FAILURE); \ } \ } while(0)
|