#ifndef _SPHO_SPHO_H #define _SPHO_SPHO_H #include #include "spho/err.h" #include "spho/ctx.h" #define SPHO_UTIL_SLIST_DESTROY(l, elmtype, next, term) \ do { \ struct elmtype *elm; \ while (! SLIST_EMPTY(l)) { \ elm = SLIST_FIRST(l); \ SLIST_REMOVE_HEAD(l, next); \ term(elm); \ free(elm); \ } \ } while (0) #ifdef SPHO_USE_STRLCPY #define SPHO_STRLCPY(dst, src, len) strlcpy(dst, src, len) #else #define SPHO_STRLCPY(dst, src, len) \ (size_t)snprintf(dst, len, "%s", src) #endif /* ifdef SPHO_USE_STRLCPY */ #define SPHO_STRINGIFY(a) #a #define SPHO_MACRO_STR(b) SPHO_STRINGIFY(b) #define SPHO_RIP(msg) \ do { \ fprintf(stderr, "SPHO_RIP(" msg ")@" \ __FILE__ ":" __LINE__S \ " failed. Aborting.\n"); \ abort(); \ } while (0) #ifdef SPHO_DEBUG #define __LINE__S SPHO_MACRO_STR(__LINE__) #define SPHO_PRECOND(cond) \ do { \ if (! (cond) ) { \ fprintf(stderr, "SPHO_PRECOND(" #cond ")@" \ __FILE__ ":" __LINE__S \ " failed. Aborting.\n"); \ abort(); \ } \ } while (0) #define SPHO_ASSERT(cond) \ do { \ if (! (cond) ) { \ fprintf(stderr, "SPHO_ASSERT(" #cond ")@" \ __FILE__ ":" __LINE__S \ " failed. Aborting.\n"); \ abort(); \ } \ } while (0) #define SPHO_POSTCOND(cond) \ do { \ if (! (cond) ) { \ fprintf(stderr, "SPHO_POSTCOND(" #cond ")@" \ __FILE__ ":" __LINE__S \ " failed. Aborting.\n"); \ abort(); \ } \ } while (0) #ifdef SPHO_ENABLE_DEBUG_PRINT #define SPHO_DEBUG_PRINT(fmt, ...) \ do { \ fprintf(stderr, fmt __VA_OPT__(,) __VA_ARGS__); \ } while (0) #else #define SPHO_DEBUG_PRINT(fmt, ...) #endif /* ifdef SPHO_ENABLE_DEBUG_PRINT */ #endif /* ifdef SPHO_DEBUG */ #endif