X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Fecoli_assert.h;h=fcd218628fc433b5cee60b6f59eb71487c0b9858;hb=51028779e0a8772091aec5ab96bcf2519cf2f1ad;hp=9779d32ef014b6b9bae3702743671c7d0e9167ee;hpb=7cbb8a1000b85db2a487afd4d17e688b8c0aa756;p=protos%2Flibecoli.git diff --git a/lib/ecoli_assert.h b/lib/ecoli_assert.h index 9779d32..fcd2186 100644 --- a/lib/ecoli_assert.h +++ b/lib/ecoli_assert.h @@ -1,12 +1,12 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2016, Olivier MATZ + * Copyright 2016, Olivier MATZ */ /** * 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