chiark / gitweb /
macro: add new assert_return() macro for early parameter checking in functions
authorLennart Poettering <lennart@poettering.net>
Thu, 10 Oct 2013 22:45:47 +0000 (00:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 10 Oct 2013 22:45:47 +0000 (00:45 +0200)
commit18387b5983150181dd9dee8edf1573285eecbaa4
tree60818e4f9000af107fc71d785e29cfd0da410360
parenteaa3cbef3b8c214cd5c2d75b04e70ad477187e17
macro: add new assert_return() macro for early parameter checking in functions

For the library functions we expose we currently repeatedly use checks
like the following:

if (!value_is_ok(parameter1))
        return -EINVAL;
if (!value_is_ok(parameter2))
        return -EINVAL;

And so on. Let's turn this into a macro:

assert_return(value_is_ok(parameter1), -EINVAL);
assert_return(value_is_ok(paramater2), -EINVAL);

This makes our code a bit shorter and simpler, and also allows us to add
a _unlikely_() around the check.
src/shared/macro.h