mirror of
https://github.com/systemd/systemd.git
synced 2024-11-07 01:27:11 +03:00
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.
This commit is contained in:
parent
eaa3cbef3b
commit
18387b5983
@ -159,6 +159,12 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
|
||||
} while (false)
|
||||
#endif
|
||||
|
||||
#define assert_return(expr, r) \
|
||||
do { \
|
||||
if (!(expr)) \
|
||||
return (r); \
|
||||
} while (false)
|
||||
|
||||
#define PTR_TO_INT(p) ((int) ((intptr_t) (p)))
|
||||
#define INT_TO_PTR(u) ((void *) ((intptr_t) (u)))
|
||||
#define PTR_TO_UINT(p) ((unsigned int) ((uintptr_t) (p)))
|
||||
|
Loading…
Reference in New Issue
Block a user