]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
common: introduce flags and var swapping macros
authorVictor Julien <victor@inliniac.net>
Fri, 27 Jul 2018 12:16:41 +0000 (14:16 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 21 Mar 2019 18:19:04 +0000 (19:19 +0100)
src/suricata-common.h

index 70337fba6f8a9542823b5f0d22ea12237e5d7e6a..859f3125301262d9998e1affea7d3fd3125ee141 100644 (file)
 #define SCNtohl(x) (uint32_t)ntohl((x))
 #define SCNtohs(x) (uint16_t)ntohs((x))
 
+/* swap flags if one of them is set, otherwise do nothing. */
+#define SWAP_FLAGS(flags, a, b)                     \
+    do {                                            \
+        if (((flags) & ((a)|(b))) == (a)) {         \
+            (flags) &= ~(a);                        \
+            (flags) |= (b);                         \
+        } else if (((flags) & ((a)|(b))) == (b)) {  \
+            (flags) &= ~(b);                        \
+            (flags) |= (a);                         \
+        }                                           \
+    } while(0)
+
+#define SWAP_VARS(type, a, b)           \
+    do {                                \
+        type t = (a);                   \
+        (a) = (b);                      \
+        (b) = t;                        \
+    } while (0)
+
 typedef enum PacketProfileDetectId_ {
     PROF_DETECT_SETUP,
     PROF_DETECT_GETSGH,