X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fmacro.h;h=3cf17bb8675b59b8b6b9f8d36bcc5c0c1fee16c7;hb=44b601bc79e46722bc0f0862ee0ce34a2284ef11;hp=2f151bcc8cb143f5c80d7d33c7de81a2d4c3236f;hpb=a3dc35472f3a48ea8445ad7a943e2ff253170417;p=elogind.git diff --git a/src/shared/macro.h b/src/shared/macro.h index 2f151bcc8..3cf17bb86 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -27,7 +27,7 @@ #include #include -#define _printf_attr_(a,b) __attribute__ ((format (printf, a, b))) +#define _printf_(a,b) __attribute__ ((format (printf, a, b))) #define _alloc_(...) __attribute__ ((alloc_size(__VA_ARGS__))) #define _sentinel_ __attribute__ ((sentinel)) #define _noreturn_ __attribute__((noreturn)) @@ -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))) @@ -271,7 +277,7 @@ do { \ * the const magic to the type, otherwise the compiler warns about * signed/unsigned comparison, because the magic can be 32 bit unsigned. */ -#define F_TYPE_CMP(a, b) (a == (typeof(a)) b) +#define F_TYPE_EQUAL(a, b) (a == (typeof(a)) b) /* Returns the number of chars needed to format variables of the @@ -284,4 +290,7 @@ do { \ sizeof(type) <= 4 ? 10 : \ sizeof(type) <= 8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)]))) +#define SET_FLAG(v, flag, b) \ + (v) = (b) ? ((v) | (flag)) : ((v) & ~(flag)) + #include "log.h"