X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fmacro.h;h=cc1c9e73c08bddcbe39ebee5ac221a14b6d547f1;hb=d896ac2d2fbce41a0b11a0618a685adeaf18b8fe;hp=ae2971fad141f54959bc89d0e50675f5faa2497a;hpb=6825a04de61f0bceab0ccddb34d825c3951caef1;p=elogind.git diff --git a/src/shared/macro.h b/src/shared/macro.h index ae2971fad..cc1c9e73c 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -67,6 +67,10 @@ _Pragma("GCC diagnostic push"); \ _Pragma("GCC diagnostic ignored \"-Wshadow\"") +#define DISABLE_WARNING_INCOMPATIBLE_POINTER_TYPES \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Wincompatible-pointer-types\"") + #define REENABLE_WARNING \ _Pragma("GCC diagnostic pop") @@ -252,6 +256,15 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { } \ } while (false) +#define assert_return_errno(expr, r, err) \ + do { \ + if (_unlikely_(!(expr))) { \ + log_assert_failed_return(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \ + errno = err; \ + 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))) @@ -379,7 +392,8 @@ do { \ /* Returns the number of chars needed to format variables of the * specified type as a decimal string. Adds in extra space for a - * negative '-' prefix. */ + * negative '-' prefix (hence works correctly on signed + * types). Includes space for the trailing NUL. */ #define DECIMAL_STR_MAX(type) \ (2+(sizeof(type) <= 1 ? 3 : \ sizeof(type) <= 2 ? 5 : \ @@ -453,4 +467,7 @@ do { \ } \ struct __useless_struct_to_allow_trailing_semicolon__ +#define CMSG_FOREACH(cmsg, mh) \ + for ((cmsg) = CMSG_FIRSTHDR(mh); (cmsg); (cmsg) = CMSG_NXTHDR((mh), (cmsg))) + #include "log.h"