notmuch_message_get_flag (notmuch_message_t *message,
notmuch_message_flag_t flag)
{
- return message->flags & (1 << flag);
+ return NOTMUCH_TEST_BIT (message->flags, flag);
}
void
notmuch_message_flag_t flag, notmuch_bool_t enable)
{
if (enable)
- message->flags |= (1 << flag);
+ NOTMUCH_SET_BIT (&message->flags, flag);
else
- message->flags &= ~(1 << flag);
+ NOTMUCH_CLEAR_BIT (&message->flags, flag);
}
time_t
#define STRNCMP_LITERAL(var, literal) \
strncmp ((var), (literal), sizeof (literal) - 1)
+/* Robust bit test/set/reset macros */
+#define NOTMUCH_TEST_BIT(val, bit) \
+ (((bit) < 0 || (bit) >= CHAR_BIT * sizeof (unsigned long long)) ? 0 \
+ : !!((val) & (1ull << (bit))))
+#define NOTMUCH_SET_BIT(valp, bit) \
+ (((bit) < 0 || (bit) >= CHAR_BIT * sizeof (unsigned long long)) ? *(valp) \
+ : (*(valp) |= (1ull << (bit))))
+#define NOTMUCH_CLEAR_BIT(valp, bit) \
+ (((bit) < 0 || (bit) >= CHAR_BIT * sizeof (unsigned long long)) ? *(valp) \
+ : (*(valp) &= ~(1ull << (bit))))
+
#define unused(x) x __attribute__ ((unused))
#ifdef __cplusplus