diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2019-05-17 19:48:37 +0200 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2019-05-17 19:48:37 +0200 |
commit | 3efe227e96843c72712e9e97d2ee1f2f5c0e1b81 (patch) | |
tree | 822f56168861efec4436233db1a8a072e30ed7ee | |
parent | 1d8d4b9a5915f6ba14dfde0c8031c1af0b1c84cc (diff) | |
download | embedlog-3efe227e96843c72712e9e97d2ee1f2f5c0e1b81.tar.gz embedlog-3efe227e96843c72712e9e97d2ee1f2f5c0e1b81.tar.bz2 embedlog-3efe227e96843c72712e9e97d2ee1f2f5c0e1b81.zip |
src/valid.h: add some more VALID macros
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r-- | src/valid.h | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/src/valid.h b/src/valid.h index b67ccf0..1eceb78 100644 --- a/src/valid.h +++ b/src/valid.h @@ -8,24 +8,62 @@ #define EL_VALID_H 1 -/* ==== include files ======================================================= */ +#include <errno.h> -#include <errno.h> +/* ========================================================================== + If expression 'x' evaluates to false, macro will set errno value to 'e' + and will force function to return with code '-1' + ========================================================================== */ -/* ==== public macros ======================================================= */ +#define VALID(e, x) if (!(x)) { errno = (e); return -1; } /* ========================================================================== - If expression 'x' evaluates to false, macro will set errno value to 'e' - and will force function to return with code '-1' + Same as VALID but when expression fails, message is printed to default + embedlog facility + ========================================================================== */ + + +#define VALIDP(e, x) if (!(x)) { el_print(ELW, "VALID FAILED "#x); \ + errno = (e); return -1; } + + +/* ========================================================================== + Same as VALIDP but message is printed to default option, defined by + EL_OPTIONS_OBJECT + ========================================================================== */ + + +#define VALIDOP(e, x) if (!(x)) { el_oprint(OELW, "VALID FAILED "#x); \ + errno = (e); return -1; } + + +/* ========================================================================== + If expression 'x' evaluates to false, macro will set errno value to 'e' + and will force function to return value 'v' + ========================================================================== */ + + +#define VALIDR(e, v, x) if (!(x)) { errno = (e); return (v); } + + +/* ========================================================================== + If expression 'x' evaluates to false, macro will set errno value to 'e' + and will jump to lable 'l' ========================================================================== */ -#define VALID(e ,x) if (!(x)) { errno = (e); return -1; } +#define VALIDG(e, l, x) if (!(x)) { errno = (e); goto l; } + + +/* ========================================================================== + If expression 'x' evaluates to false, macro will call code 'c', set + errno to 'e', and return -1 + ========================================================================== */ -#define VALIDGO(e, x, l) if (!(x)) { errno = (e); goto l; } +#define VALIDC(e, x, c) if (!(x)) { c; errno = (e); return -1; } #endif |