#ifndef _SPHO_ERR_H #define _SPHO_ERR_H #define SPHO_ERR_SYSTEM 0x000001 #define SPHO_ERR_INTERNAL 0x010001 #define SPHO_ERR_IS_SYSERR(err) (SPHO_ERR_SYSTEM == err) #ifdef SPHO_DEBUG #define SPHO_ERR(ctx, err) \ do { \ ctx->err = err; \ if (err == SPHO_ERR_SYSTEM) \ ctx->err_info = errno; \ snprintf(ctx->filebuf, sizeof(ctx->filebuf), "%s", \ __FILE__); \ ctx->errline = __LINE__; \ } while (0) #else /* SPHO_DEBUG */ #define SPHO_ERR(ctx, err) \ do { \ ctx->err = err; \ if (err == SPHO_ERR_SYSTEM) \ ctx->err_info = errno; \ } while (0) #endif /* SPHO_DEBUG */ /* debug stuff */ #ifdef SPHO_DEBUG /* PRECOND/ASSERT/POSTCOND */ #define SPHO_PRECOND(cond) do { \ if (! (cond) ) { \ fprintf(stderr, "SPHO_PRECOND(" #cond ")@" __FILE__ ":" __LINE__ \ " failed. Aborting."); \ abort(); \ } \ } while (0) #define SPHO_ASSERT(cond) do { \ if (! (cond) ) { \ fprintf(stderr, "SPHO_ASSERT(" #cond ")@" __FILE__ ":" __LINE__ \ " failed. Aborting."); \ abort(); \ } \ } while (0) #define SPHO_POSTCOND(cond) do { \ if (! (cond) ) { \ fprintf(stderr, "SPHO_POSTCOND(" #cond ")@" __FILE__ ":" __LINE__ \ " failed. Aborting."); \ abort(); \ } \ } while (0) #else #define SPHO_PRECOND(cond) #define SPHO_ASSERT(cond) #define SPHO_POSTCOND(cond) #endif #endif