From bbcdbe61bd360df42d590689c980286d670b11b9 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Sun, 24 Jun 2012 18:16:12 +0200 Subject: [PATCH] llop: add default helpers We often need to return the same message over and over again with the same return value. Use default log-messages now instead of ignoring the log. Signed-off-by: David Herrmann --- src/llog.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/llog.h b/src/llog.h index 6213cf0..5da5b49 100644 --- a/src/llog.h +++ b/src/llog.h @@ -138,4 +138,43 @@ static const char *LLOG_SUBSYSTEM __attribute__((__unused__)); #define llog_err llog_error #define llog_crit llog_critical +/* + * Default log messages + * These macros can be used to produce default log messages. You can use them + * directly in an "return" statement. The "v" variants automatically cast the + * result to void so it can be used in return statements inside of void + * functions. The "d" variants use the logging object directly as the parent + * might not exist, yet. + * + * Most of the messages work only if debugging is enabled. This is, because they + * are used in debug paths and would slow down normal applications. + */ + +#define llog_dEINVAL(obj) \ + (llog_ddebug((obj), "invalid arguments"), -EINVAL) +#define llog_EINVAL(obj) \ + (llog_dEINVAL((obj)->llog)) +#define llog_vEINVAL(obj) \ + ((void)llog_EINVAL(obj)) +#define llog_vdEINVAL(obj) \ + ((void)llog_dEINVAL(obj)) + +#define llog_dEFAULT(obj) \ + (llog_ddebug((obj), "operation failed"), -EFAULT) +#define llog_EFAULT(obj) \ + (llog_dEFAULT((obj)->llog)) +#define llog_vEFAULT(obj) \ + ((void)llog_EFAULT(obj)) +#define llog_vdEFAULT(obj) \ + ((void)llog_dEFAULT(obj)) + +#define llog_dENOMEM(obj) \ + (llog_ddebug((obj), "memory allocation failed"), -ENOMEM) +#define llog_ENOMEM(obj) \ + (llog_dENOMEM((obj)->llog)) +#define llog_vENOMEM(obj) \ + ((void)llog_ENOMEM(obj)) +#define llog_vdENOMEM(obj) \ + ((void)llog_dENOMEM(obj)) + #endif /* LLOG_H_INCLUDED */