#ifndef _LSUP_CORE_H #define _LSUP_CORE_H #include #include #include #include #include #include #include #ifdef DEBUG #define DEBUG_TEST 1 #else #define DEBUG_TEST 0 #endif #define STR "%s\n" #define TRACE(fmt, ...) \ do {\ if (DEBUG_TEST) \ fprintf(stderr, "%s:%d:%s(): " fmt "\n", \ __FILE__, __LINE__, __func__, __VA_ARGS__); \ } while (0) #define LIKELY(x) __builtin_expect(!!(x), true) #define UNLIKELY(x) __builtin_expect(!!(x), false) // TODO Handle memory errors better. #define CRITICAL(exp) if (UNLIKELY(((exp) == NULL))) { abort(); } #define KLEN sizeof(LSUP_Key) #define DBL_KLEN sizeof(LSUP_DoubleKey) #define TRP_KLEN sizeof(LSUP_TripleKey) #define QUAD_KLEN sizeof(LSUP_QuadKey) # define UUIDSTR_SIZE 37 // Handy flags operations. #define SET_FLAG(n, f) ((n) |= (f)) #define CLR_FLAG(n, f) ((n) &= ~(f)) #define TGL_FLAG(n, f) ((n) ^= (f)) #define CHK_FLAG(n, f) ((n) & (f)) /* * * RETURN CODES * * */ /** * 0 is success, positive integers (>88800) are warnings, and negative integers * (<-88800) are errors. */ #define LSUP_OK 0 #define LSUP_NOACTION 88801 #define LSUP_NORESULT 88802 #define LSUP_END 88803 #define LSUP_ERROR (-88801) #define LSUP_PARSE_ERR (-88802) #define LSUP_VALUE_ERR (-88803) typedef size_t LSUP_Key; typedef LSUP_Key LSUP_DoubleKey[2]; typedef LSUP_Key LSUP_TripleKey[3]; typedef LSUP_Key LSUP_QuadKey[4]; typedef char uuid_str_t[UUIDSTR_SIZE]; // Don't use MIN and MAX macros: see // https://dustri.org/b/min-and-max-macro-considered-harmful.html inline int min(int x, int y) { return x < y ? x : y; } inline int max(int x, int y) { return x > y ? x : y; } #endif