X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fmacro.h;h=7ae1ed80b6d0d9658672e3bc58d0f6084ad1d7f7;hb=30ab6a0fc1bb950c4dcd90dcd3dfe00a810c7fc1;hp=e88630fa04deab1dbce89a0f2668b1758637f0b6;hpb=df99a9ef5bb7a89b92ccfb103b2f3e7046c62ef5;p=elogind.git diff --git a/src/shared/macro.h b/src/shared/macro.h index e88630fa0..7ae1ed80b 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -256,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))) @@ -383,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 : \