84b277
From 87eaadf84215ef31e453d26c4935f82ec7ab1ef0 Mon Sep 17 00:00:00 2001
84b277
From: Lennart Poettering <lennart@poettering.net>
84b277
Date: Tue, 3 Dec 2013 16:41:06 +0100
84b277
Subject: [PATCH] macro: better make IN_SET() macro use const arrays
84b277
84b277
Conflicts:
84b277
	src/shared/macro.h
84b277
84b277
(cherry-picked from 059d9fbb)
84b277
84b277
Resolves: #1147524
84b277
---
84b277
 src/shared/macro.h | 14 ++++++++++++++
84b277
 1 file changed, 14 insertions(+)
84b277
84b277
diff --git a/src/shared/macro.h b/src/shared/macro.h
84b277
index d4f92b6..27a02d4 100644
84b277
--- a/src/shared/macro.h
84b277
+++ b/src/shared/macro.h
84b277
@@ -287,4 +287,18 @@ do {                                                                    \
84b277
 #define SET_FLAG(v, flag, b) \
84b277
         (v) = (b) ? ((v) | (flag)) : ((v) & ~(flag))
84b277
 
84b277
+#define IN_SET(x, ...)                                                  \
84b277
+        ({                                                              \
84b277
+                const typeof(x) _x = (x);                               \
84b277
+                unsigned _i;                                            \
84b277
+                bool _found = false;                                    \
84b277
+                for (_i = 0; _i < sizeof((const typeof(_x)[]) { __VA_ARGS__ })/sizeof(const typeof(_x)); _i++) \
84b277
+                        if (((const typeof(_x)[]) { __VA_ARGS__ })[_i] == _x) { \
84b277
+                                _found = true;                          \
84b277
+                                break;                                  \
84b277
+                        }                                               \
84b277
+                _found;                                                 \
84b277
+        })
84b277
+
84b277
+
84b277
 #include "log.h"