From: HisShadow Date: Tue, 25 Oct 2022 17:43:21 +0000 (+0300) Subject: Unroll IN_SET since the max usage is 2 elements check X-Git-Tag: v6.0.0~80^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4deaa28c04c6c475ec554eec7572e6a99e637394;p=thirdparty%2Flxc.git Unroll IN_SET since the max usage is 2 elements check Signed-off-by: HisShadow --- diff --git a/src/lxc/commands.c b/src/lxc/commands.c index 946c72e95..07be1d535 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -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)); diff --git a/src/lxc/conf.c b/src/lxc/conf.c index bc1b25464..b3c52835b 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -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); diff --git a/src/lxc/error_utils.h b/src/lxc/error_utils.h index 614dd344a..df1899d61 100644 --- a/src/lxc/error_utils.h +++ b/src/lxc/error_utils.h @@ -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 */ diff --git a/src/lxc/file_utils.c b/src/lxc/file_utils.c index 5ee2bea9e..2e47f7ea9 100644 --- a/src/lxc/file_utils.c +++ b/src/lxc/file_utils.c @@ -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); diff --git a/src/lxc/network.c b/src/lxc/network.c index 81efc8a7a..333f54255 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -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; /* diff --git a/src/lxc/string_utils.c b/src/lxc/string_utils.c index c14a38dfe..e62612636 100644 --- a/src/lxc/string_utils.c +++ b/src/lxc/string_utils.c @@ -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;