]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Unroll IN_SET since the max usage is 2 elements check 4209/head
authorHisShadow <shadowpilot34@gmail.com>
Tue, 25 Oct 2022 17:43:21 +0000 (20:43 +0300)
committerHisShadow <shadowpilot34@gmail.com>
Tue, 25 Oct 2022 17:44:16 +0000 (20:44 +0300)
Signed-off-by: HisShadow <shadowpilot34@gmail.com>
src/lxc/commands.c
src/lxc/conf.c
src/lxc/error_utils.h
src/lxc/file_utils.c
src/lxc/network.c
src/lxc/string_utils.c

index 946c72e959478ebc022a6cc8f838c1b7a3f373ff..07be1d53539a97373c00749af81277958e4a5bed 100644 (file)
@@ -508,7 +508,7 @@ static ssize_t lxc_cmd(const char *name, struct lxc_cmd_rr *cmd, bool *stopped,
 
        client_fd = lxc_cmd_send(name, cmd, lxcpath, hashed_sock_name);
        if (client_fd < 0) {
-               if (IN_SET(errno, ECONNREFUSED, EPIPE))
+               if (errno == ECONNREFUSED || errno == EPIPE)
                        *stopped = 1;
 
                return systrace("Command \"%s\" failed to connect command socket", lxc_cmd_str(cmd->req.cmd));
index bc1b254642110cbce8c90277ba977d2da53813ec..b3c52835b4c3f05c3096b64bccd78d86f3c9530f 100644 (file)
@@ -958,7 +958,7 @@ static int open_ttymnt_at(int dfd, const char *path)
                     PROTECT_LOOKUP_BENEATH,
                     0);
        if (fd < 0) {
-               if (!IN_SET(errno, ENXIO, EEXIST))
+               if (errno != ENXIO && errno != EEXIST)
                        return syserror("Failed to create \"%d/\%s\"", dfd, path);
 
                SYSINFO("Failed to create \"%d/\%s\"", dfd, path);
index 614dd344a2e6748d507c5e4c3e639805ff513da7..df1899d61be515e10ba2a511ec4f078327b4bdd8 100644 (file)
@@ -46,61 +46,9 @@ static inline int PTR_RET(const void *ptr)
                return 0;
 }
 
-/* Taken from Lennart tyvm. */
-#define CASE_F(X) case X:
-#define CASE_F_1(CASE, X) CASE_F(X)
-#define CASE_F_2(CASE, X, ...)  CASE(X) CASE_F_1(CASE, __VA_ARGS__)
-#define CASE_F_3(CASE, X, ...)  CASE(X) CASE_F_2(CASE, __VA_ARGS__)
-#define CASE_F_4(CASE, X, ...)  CASE(X) CASE_F_3(CASE, __VA_ARGS__)
-#define CASE_F_5(CASE, X, ...)  CASE(X) CASE_F_4(CASE, __VA_ARGS__)
-#define CASE_F_6(CASE, X, ...)  CASE(X) CASE_F_5(CASE, __VA_ARGS__)
-#define CASE_F_7(CASE, X, ...)  CASE(X) CASE_F_6(CASE, __VA_ARGS__)
-#define CASE_F_8(CASE, X, ...)  CASE(X) CASE_F_7(CASE, __VA_ARGS__)
-#define CASE_F_9(CASE, X, ...)  CASE(X) CASE_F_8(CASE, __VA_ARGS__)
-#define CASE_F_10(CASE, X, ...) CASE(X) CASE_F_9(CASE, __VA_ARGS__)
-#define CASE_F_11(CASE, X, ...) CASE(X) CASE_F_10(CASE, __VA_ARGS__)
-#define CASE_F_12(CASE, X, ...) CASE(X) CASE_F_11(CASE, __VA_ARGS__)
-#define CASE_F_13(CASE, X, ...) CASE(X) CASE_F_12(CASE, __VA_ARGS__)
-#define CASE_F_14(CASE, X, ...) CASE(X) CASE_F_13(CASE, __VA_ARGS__)
-#define CASE_F_15(CASE, X, ...) CASE(X) CASE_F_14(CASE, __VA_ARGS__)
-#define CASE_F_16(CASE, X, ...) CASE(X) CASE_F_15(CASE, __VA_ARGS__)
-#define CASE_F_17(CASE, X, ...) CASE(X) CASE_F_16(CASE, __VA_ARGS__)
-#define CASE_F_18(CASE, X, ...) CASE(X) CASE_F_17(CASE, __VA_ARGS__)
-#define CASE_F_19(CASE, X, ...) CASE(X) CASE_F_18(CASE, __VA_ARGS__)
-#define CASE_F_20(CASE, X, ...) CASE(X) CASE_F_19(CASE, __VA_ARGS__)
-
-#define GET_CASE_F(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,NAME,...) NAME
-#define FOR_EACH_MAKE_CASE(...) \
-        GET_CASE_F(__VA_ARGS__,CASE_F_20,CASE_F_19,CASE_F_18,CASE_F_17,CASE_F_16,CASE_F_15,CASE_F_14,CASE_F_13,CASE_F_12,CASE_F_11, \
-                               CASE_F_10,CASE_F_9,CASE_F_8,CASE_F_7,CASE_F_6,CASE_F_5,CASE_F_4,CASE_F_3,CASE_F_2,CASE_F_1) \
-                   (CASE_F,__VA_ARGS__)
-
-#define XCONCATENATE(x, y) x ## y
-#define CONCATENATE(x, y) XCONCATENATE(x, y)
-
-#define assert_static(expr)                                \
-       struct CONCATENATE(_assert_struct_, __COUNTER__) { \
-               char x[(expr) ? 0 : -1];                   \
-       }
-
-#define IN_SET(x, ...)                                                      \
-       ({                                                                  \
-               bool _found = false;                                        \
-               static const long double __assert_in_set[] __lxc_unused = { \
-                   __VA_ARGS__};                                           \
-               assert_static(ARRAY_SIZE(__assert_in_set) <= 20);           \
-               switch (x) {                                                \
-                       FOR_EACH_MAKE_CASE(__VA_ARGS__)                     \
-                       _found = true;                                      \
-                       break;                                              \
-               default:                                                    \
-                       break;                                              \
-               }                                                           \
-               _found;                                                     \
-       })
-
 static inline bool ERRNO_IS_NOT_SUPPORTED(int r) {
-       return IN_SET(abs(r), EOPNOTSUPP, ENOSYS);
+       int x = abs(r);
+       return x == EOPNOTSUPP || x == ENOSYS;
 }
 
 #endif /* __LXC_ERROR_UTILS_H */
index 5ee2bea9e5fa50860f52883e7843ac94ceb37c19..2e47f7ea906592020f673316fd63893e8f3ee851 100644 (file)
@@ -796,7 +796,7 @@ bool same_device(int fda, const char *patha, int fdb, const char *pathb)
        errno = EINVAL;
        modea = (st_fda.st_mode & S_IFMT);
        modeb = (st_fdb.st_mode & S_IFMT);
-       if (modea != modeb || !IN_SET(modea, S_IFCHR, S_IFBLK))
+       if (modea != modeb || !(modea == S_IFCHR || modea == S_IFBLK))
                return false;
 
        return (st_fda.st_rdev == st_fdb.st_rdev);
index 81efc8a7a4b64b6208bfb88c624da4f785a00768..333f54255f1c9a47c2aa82edfad02c18e28e8b94 100644 (file)
@@ -3504,7 +3504,7 @@ static int create_transient_name(struct lxc_netdev *netdev)
 
 static int netdev_requires_move(const struct lxc_netdev *netdev)
 {
-       if (IN_SET(netdev->type, LXC_NET_EMPTY, LXC_NET_NONE))
+       if (netdev->type == LXC_NET_EMPTY || netdev->type == LXC_NET_NONE)
                return false;
 
        /*
index c14a38dfebe56b5baca7922af1fbea613a9673e8..e62612636677582b1c76755ee0d57dd3f8f78b61 100644 (file)
@@ -203,7 +203,7 @@ char *path_simplify(const char *path)
        absolute = abspath(path_new);
 
        f = path_new;
-       if (*f == '.' && IN_SET(f[1], 0, '/')) {
+       if (*f == '.' && (f[1] == 0 || f[1] == '/')) {
                ignore_slash = true;
                f++;
        }
@@ -216,7 +216,7 @@ char *path_simplify(const char *path)
                }
 
                if (slash) {
-                       if (*f == '.' && IN_SET(f[1], 0, '/'))
+                       if (*f == '.' && (f[1] == 0 || f[1] == '/'))
                                continue;
 
                        slash = false;