X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Fecoli_assert.h;h=fcd218628fc433b5cee60b6f59eb71487c0b9858;hb=15718f19cbf3868bf6fba79f4e26b5254c57873e;hp=b1ef0ecaf7b139f5c222f5d19e20f42c0b512742;hpb=0a2b19af9303c4a0ec05bea7afe1803a429517bf;p=protos%2Flibecoli.git diff --git a/lib/ecoli_assert.h b/lib/ecoli_assert.h index b1ef0ec..fcd2186 100644 --- a/lib/ecoli_assert.h +++ b/lib/ecoli_assert.h @@ -5,8 +5,8 @@ /** * Assert API * - * Helpers to check at runtime if a condition is true, and abort - * (exit) otherwise. + * Helpers to check at runtime if a condition is true, or otherwise + * either abort (exit program) or return an error. */ #ifndef ECOLI_ASSERT_ @@ -32,4 +32,24 @@ void __ec_assert_print(bool expr, const char *expr_str, const char *format, ...); +/** + * Check a condition or return. + * + * If the condition is true, do nothing. If it is false, set + * errno and return the specified value. + * + * @param cond + * The condition to test. + * @param ret + * The value to return. + * @param err + * The errno to set. + */ +#define EC_CHECK_ARG(cond, ret, err) do { \ + if (!(cond)) { \ + errno = err; \ + return ret; \ + } \ + } while(0) + #endif