From: Mike Yuan Date: Thu, 26 Dec 2024 19:30:12 +0000 (+0100) Subject: tree-wide: replace FLAGS_SET(..., 1 << v) with BIT_SET(..., v) X-Git-Tag: v258-rc1~1762^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F35760%2Fhead;p=thirdparty%2Fsystemd.git tree-wide: replace FLAGS_SET(..., 1 << v) with BIT_SET(..., v) --- diff --git a/src/basic/cap-list.c b/src/basic/cap-list.c index b4fe75a37e8..2df2887446f 100644 --- a/src/basic/cap-list.c +++ b/src/basic/cap-list.c @@ -4,6 +4,7 @@ #include #include "alloc-util.h" +#include "bitfield.h" #include "capability-util.h" #include "cap-list.h" #include "extract-word.h" @@ -83,7 +84,7 @@ int capability_set_to_string(uint64_t set, char **ret) { for (unsigned i = 0; i <= cap_last_cap(); i++) { const char *p; - if (!FLAGS_SET(set, UINT64_C(1) << i)) + if (!BIT_SET(set, i)) continue; p = CAPABILITY_TO_STRING(i); @@ -143,7 +144,7 @@ int capability_set_to_strv(uint64_t set, char ***ret) { for (unsigned i = 0; i <= cap_last_cap(); i++) { const char *p; - if (!FLAGS_SET(set, UINT64_C(1) << i)) + if (!BIT_SET(set, i)) continue; p = CAPABILITY_TO_STRING(i); diff --git a/src/basic/compress.c b/src/basic/compress.c index 06db2eed7d7..61e87adddee 100644 --- a/src/basic/compress.c +++ b/src/basic/compress.c @@ -18,6 +18,7 @@ #endif #include "alloc-util.h" +#include "bitfield.h" #include "compress.h" #include "fd-util.h" #include "fileio.h" @@ -124,7 +125,10 @@ bool compression_supported(Compression c) { (1U << COMPRESSION_LZ4) * HAVE_LZ4 | (1U << COMPRESSION_ZSTD) * HAVE_ZSTD; - return c >= 0 && c < _COMPRESSION_MAX && FLAGS_SET(supported, 1U << c); + assert(c >= 0); + assert(c < _COMPRESSION_MAX); + + return BIT_SET(supported, c); } #if HAVE_XZ diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 3c66d698932..47d919a014d 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -7,6 +7,7 @@ #include "alloc-util.h" #include "architecture.h" +#include "bitfield.h" #include "build.h" #include "bus-common-errors.h" #include "bus-get-properties.h" @@ -2085,9 +2086,9 @@ static int method_enqueue_marked_jobs(sd_bus_message *message, void *userdata, s continue; BusUnitQueueFlags flags; - if (FLAGS_SET(u->markers, 1u << UNIT_MARKER_NEEDS_RESTART)) + if (BIT_SET(u->markers, UNIT_MARKER_NEEDS_RESTART)) flags = 0; - else if (FLAGS_SET(u->markers, 1u << UNIT_MARKER_NEEDS_RELOAD)) + else if (BIT_SET(u->markers, UNIT_MARKER_NEEDS_RELOAD)) flags = BUS_UNIT_QUEUE_RELOAD_IF_POSSIBLE; else continue; diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 03f25402a28..6dca2d93bdb 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -3,6 +3,7 @@ #include "sd-bus.h" #include "alloc-util.h" +#include "bitfield.h" #include "bpf-firewall.h" #include "bus-common-errors.h" #include "bus-get-properties.h" @@ -72,7 +73,7 @@ static int property_get_can_clean( return r; for (ExecDirectoryType t = 0; t < _EXEC_DIRECTORY_TYPE_MAX; t++) { - if (!FLAGS_SET(mask, 1U << t)) + if (!BIT_SET(mask, t)) continue; r = sd_bus_message_append(reply, "s", exec_resource_type_to_string(t)); @@ -353,15 +354,11 @@ static int property_get_markers( if (r < 0) return r; - /* Make sure out values fit in the bitfield. */ - assert_cc(_UNIT_MARKER_MAX <= sizeof(((Unit){}).markers) * 8); - - for (UnitMarker m = 0; m < _UNIT_MARKER_MAX; m++) - if (FLAGS_SET(*markers, 1u << m)) { - r = sd_bus_message_append(reply, "s", unit_marker_to_string(m)); - if (r < 0) - return r; - } + BIT_FOREACH(m, *markers) { + r = sd_bus_message_append(reply, "s", unit_marker_to_string(m)); + if (r < 0) + return r; + } return sd_bus_message_close_container(reply); } diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index ff616813f61..c58698e5649 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -22,6 +22,7 @@ #endif #include "argv-util.h" #include "barrier.h" +#include "bitfield.h" #include "bpf-dlopen.h" #include "bpf-restrict-fs.h" #include "btrfs-util.h" @@ -5359,7 +5360,7 @@ int exec_invoke( } if (keep_seccomp_privileges) { - if (!FLAGS_SET(capability_ambient_set, (UINT64_C(1) << CAP_SETUID))) { + if (!BIT_SET(capability_ambient_set, CAP_SETUID)) { r = drop_capability(CAP_SETUID); if (r < 0) { *exit_status = EXIT_USER; @@ -5585,7 +5586,7 @@ int exec_invoke( /* Only drop CAP_SYS_ADMIN if it's not in the bounding set, otherwise we'll break * applications that use it. */ - if (!FLAGS_SET(saved_bset, (UINT64_C(1) << CAP_SYS_ADMIN))) { + if (!BIT_SET(saved_bset, CAP_SYS_ADMIN)) { r = drop_capability(CAP_SYS_ADMIN); if (r < 0) { *exit_status = EXIT_USER; @@ -5595,7 +5596,7 @@ int exec_invoke( /* Only drop CAP_SETPCAP if it's not in the bounding set, otherwise we'll break * applications that use it. */ - if (!FLAGS_SET(saved_bset, (UINT64_C(1) << CAP_SETPCAP))) { + if (!BIT_SET(saved_bset, CAP_SETPCAP)) { r = drop_capability(CAP_SETPCAP); if (r < 0) { *exit_status = EXIT_USER; diff --git a/src/core/execute.c b/src/core/execute.c index f12667f1754..2ce67f9dbdd 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -20,6 +20,7 @@ #include "af-list.h" #include "alloc-util.h" #include "async.h" +#include "bitfield.h" #include "cap-list.h" #include "capability-util.h" #include "cgroup-setup.h" @@ -1666,7 +1667,7 @@ int exec_context_get_clean_directories( assert(ret); for (ExecDirectoryType t = 0; t < _EXEC_DIRECTORY_TYPE_MAX; t++) { - if (!FLAGS_SET(mask, 1U << t)) + if (!BIT_SET(mask, t)) continue; if (!prefix[t]) diff --git a/src/core/unit-serialize.c b/src/core/unit-serialize.c index 82102c0c327..82789fdbf44 100644 --- a/src/core/unit-serialize.c +++ b/src/core/unit-serialize.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "bitfield.h" #include "bpf-restrict-ifaces.h" #include "bpf-socket-bind.h" #include "bus-util.h" @@ -24,9 +25,8 @@ static int serialize_markers(FILE *f, unsigned markers) { bool space = false; fputs("markers=", f); - for (UnitMarker m = 0; m < _UNIT_MARKER_MAX; m++) - if (FLAGS_SET(markers, 1u << m)) - fputs_with_separator(f, unit_marker_to_string(m), /* separator = */ NULL, &space); + BIT_FOREACH(m, markers) + fputs_with_separator(f, unit_marker_to_string(m), /* separator = */ NULL, &space); fputc('\n', f); return 0; } @@ -496,9 +496,8 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) { if (u->markers != 0) { fprintf(f, "%s\tMarkers:", prefix); - for (UnitMarker marker = 0; marker < _UNIT_MARKER_MAX; marker++) - if (FLAGS_SET(u->markers, 1u << marker)) - fprintf(f, " %s", unit_marker_to_string(marker)); + BIT_FOREACH(marker, u->markers) + fprintf(f, " %s", unit_marker_to_string(marker)); fputs("\n", f); } diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index ba50b59f922..2c2fcb3fdeb 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -10,6 +10,7 @@ #include "sd-json.h" #include "alloc-util.h" +#include "bitfield.h" #include "bus-common-errors.h" #include "bus-get-properties.h" #include "bus-log-control-api.h" @@ -88,7 +89,7 @@ static void context_reset(Context *c, uint64_t mask) { assert(c); for (int p = 0; p < _PROP_MAX; p++) { - if (!FLAGS_SET(mask, UINT64_C(1) << p)) + if (!BIT_SET(mask, p)) continue; c->data[p] = mfree(c->data[p]); diff --git a/src/libsystemd/sd-journal/mmap-cache.c b/src/libsystemd/sd-journal/mmap-cache.c index ce8aff3c5c1..49e1e5fc814 100644 --- a/src/libsystemd/sd-journal/mmap-cache.c +++ b/src/libsystemd/sd-journal/mmap-cache.c @@ -5,6 +5,7 @@ #include #include "alloc-util.h" +#include "bitfield.h" #include "errno-util.h" #include "fd-util.h" #include "hashmap.h" @@ -109,7 +110,7 @@ static Window* window_unlink(Window *w) { } for (unsigned i = 0; i < _MMAP_CACHE_CATEGORY_MAX; i++) - if (FLAGS_SET(w->flags, 1u << i)) + if (BIT_SET(w->flags, i)) assert_se(TAKE_PTR(m->windows_by_category[i]) == w); return LIST_REMOVE(windows, w->fd->windows, w); @@ -193,7 +194,7 @@ static void category_detach_window(MMapCache *m, MMapCacheCategory c) { if (!w) return; /* Nothing attached. */ - assert(FLAGS_SET(w->flags, 1u << c)); + assert(BIT_SET(w->flags, c)); w->flags &= ~(1u << c); if (WINDOW_IS_UNUSED(w)) { diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 712438f4b1e..2ce8f628a38 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -5,6 +5,7 @@ #include "sd-messages.h" #include "alloc-util.h" +#include "bitfield.h" #include "bus-error.h" #include "bus-unit-util.h" #include "bus-util.h" @@ -158,7 +159,7 @@ int handle_action_get_enabled_sleep_actions(HandleActionSleepMask mask, char *** assert(ret); FOREACH_ELEMENT(i, sleep_actions) - if (FLAGS_SET(mask, 1U << *i)) { + if (BIT_SET(mask, *i)) { r = strv_extend(&actions, handle_action_to_string(*i)); if (r < 0) return r; diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index bc5bfb8e834..d0f0282075c 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -5,6 +5,7 @@ #include "af-list.h" #include "alloc-util.h" +#include "bitfield.h" #include "firewall-util.h" #include "in-addr-prefix-util.h" #include "logarithm.h" @@ -84,7 +85,7 @@ int address_flags_to_string_alloc(uint32_t flags, int family, char **ret) { assert(ret); for (size_t i = 0; i < ELEMENTSOF(map); i++) - if (FLAGS_SET(flags, 1 << i) && map[i]) + if (BIT_SET(flags, i) && map[i]) if (!strextend_with_separator( &str, ",", family == AF_INET6 && (1 << i) == IFA_F_SECONDARY ? "temporary" : map[i])) diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 22756fc8fbf..3f816d7fa25 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -13,6 +13,7 @@ #include "alloc-util.h" #include "arphrd-util.h" #include "batadv.h" +#include "bitfield.h" #include "bond.h" #include "bridge.h" #include "bus-util.h" @@ -2988,7 +2989,7 @@ int link_flags_to_string_alloc(uint32_t flags, char **ret) { assert(ret); for (size_t i = 0; i < ELEMENTSOF(map); i++) - if (FLAGS_SET(flags, 1 << i) && map[i]) + if (BIT_SET(flags, i) && map[i]) if (!strextend_with_separator(&str, ",", map[i])) return -ENOMEM; diff --git a/src/network/networkd-route-util.c b/src/network/networkd-route-util.c index dc9663e24b6..6b9810f934d 100644 --- a/src/network/networkd-route-util.c +++ b/src/network/networkd-route-util.c @@ -3,6 +3,7 @@ #include #include "alloc-util.h" +#include "bitfield.h" #include "logarithm.h" #include "missing_threads.h" #include "networkd-address.h" @@ -405,7 +406,7 @@ int route_flags_to_string_alloc(uint32_t flags, char **ret) { assert(ret); for (size_t i = 0; i < ELEMENTSOF(map); i++) - if (FLAGS_SET(flags, 1 << i) && map[i]) + if (BIT_SET(flags, i) && map[i]) if (!strextend_with_separator(&str, ",", map[i])) return -ENOMEM; diff --git a/src/network/networkd-util.c b/src/network/networkd-util.c index 0a40d81edd6..5db89c60472 100644 --- a/src/network/networkd-util.c +++ b/src/network/networkd-util.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "bitfield.h" #include "condition.h" #include "conf-parser.h" #include "escape.h" @@ -38,12 +39,9 @@ int network_config_state_to_string_alloc(NetworkConfigState s, char **ret) { assert(ret); for (size_t i = 0; i < ELEMENTSOF(states); i++) - if (FLAGS_SET(s, 1 << i)) { - assert(states[i]); - - if (!strextend_with_separator(&buf, ",", states[i])) + if (BIT_SET(s, i)) + if (!strextend_with_separator(&buf, ",", ASSERT_PTR(states[i]))) return -ENOMEM; - } *ret = TAKE_PTR(buf); return 0; diff --git a/src/pcrlock/pcrlock.c b/src/pcrlock/pcrlock.c index 03611d507c4..9562bf2a892 100644 --- a/src/pcrlock/pcrlock.c +++ b/src/pcrlock/pcrlock.c @@ -10,6 +10,7 @@ #include "sd-varlink.h" #include "ask-password-api.h" +#include "bitfield.h" #include "blockdev-util.h" #include "boot-entry.h" #include "build.h" @@ -2260,7 +2261,7 @@ static int show_pcr_table(EventLog *el, sd_json_variant **ret_variant) { bool fully_recognized = el->registers[pcr].fully_recognized; /* Whether any unmatched components touch this PCR */ - bool missing_components = FLAGS_SET(el->missing_component_pcrs, UINT32_C(1) << pcr); + bool missing_components = BIT_SET(el->missing_component_pcrs, pcr); const char *emoji = special_glyph( !hash_match ? SPECIAL_GLYPH_DEPRESSED_SMILEY : @@ -2675,7 +2676,7 @@ static int event_log_pcr_mask_checks_out(EventLog *el, uint32_t mask) { for (uint32_t pcr = 0; pcr < TPM2_PCRS_MAX; pcr++) { - if (!FLAGS_SET(mask, UINT32_C(1) << pcr)) + if (!BIT_SET(mask, pcr)) continue; if (!event_log_pcr_checks_out(el, el->registers + pcr)) @@ -2815,7 +2816,7 @@ static int make_pcrlock_record_from_stream( for (uint32_t i = 0; i < TPM2_PCRS_MAX; i++) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *record = NULL; - if (!FLAGS_SET(pcr_mask, UINT32_C(1) << i)) + if (!BIT_SET(pcr_mask, i)) continue; r = sd_json_buildo( @@ -3669,7 +3670,7 @@ static int verb_lock_pe(int argc, char *argv[], void *userdata) { for (uint32_t i = 0; i < TPM2_PCRS_MAX; i++) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *digests = NULL; - if (!FLAGS_SET(arg_pcr_mask, UINT32_C(1) << i)) + if (!BIT_SET(arg_pcr_mask, i)) continue; FOREACH_ARRAY(pa, tpm2_hash_algorithms, TPM2_N_HASH_ALGORITHMS) { @@ -3894,7 +3895,7 @@ static int event_log_reduce_to_safe_pcrs(EventLog *el, uint32_t *pcrs) { for (uint32_t pcr = 0; pcr < TPM2_PCRS_MAX; pcr++) { - if (!FLAGS_SET(*pcrs, UINT32_C(1) << pcr)) + if (!BIT_SET(*pcrs, pcr)) continue; if (!event_log_pcr_checks_out(el, el->registers + pcr)) { @@ -3907,7 +3908,7 @@ static int event_log_reduce_to_safe_pcrs(EventLog *el, uint32_t *pcrs) { goto drop; } - if (FLAGS_SET(el->missing_component_pcrs, UINT32_C(1) << pcr)) { + if (BIT_SET(el->missing_component_pcrs, pcr)) { log_notice("PCR %" PRIu32 " (%s) is touched by component we can't find in event log. Removing from set of PCRs.", pcr, strna(tpm2_pcr_index_to_string(pcr))); goto drop; } @@ -4191,7 +4192,7 @@ static int event_log_show_predictions(Tpm2PCRPrediction *context, uint16_t alg) for (uint32_t pcr = 0; pcr < TPM2_PCRS_MAX; pcr++) { Tpm2PCRPredictionResult *result; - if (!FLAGS_SET(context->pcrs, UINT32_C(1) << pcr)) + if (!BIT_SET(context->pcrs, pcr)) continue; if (ordered_set_isempty(context->results[pcr])) { @@ -4240,7 +4241,7 @@ static int tpm2_pcr_prediction_run( for (uint32_t pcr = 0; pcr < TPM2_PCRS_MAX; pcr++) { _cleanup_free_ Tpm2PCRPredictionResult *result = NULL; - if (!FLAGS_SET(context->pcrs, UINT32_C(1) << pcr)) + if (!BIT_SET(context->pcrs, pcr)) continue; result = new0(Tpm2PCRPredictionResult, 1); diff --git a/src/shared/fdisk-util.c b/src/shared/fdisk-util.c index 20f32d19aff..368bec2b8b8 100644 --- a/src/shared/fdisk-util.c +++ b/src/shared/fdisk-util.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "bitfield.h" #include "dissect-image.h" #include "extract-word.h" #include "fd-util.h" @@ -149,7 +150,7 @@ int fdisk_partition_set_attrs_as_uint64(struct fdisk_partition *pa, uint64_t fla assert(pa); for (unsigned i = 0; i < sizeof(flags) * 8; i++) { - if (!FLAGS_SET(flags, UINT64_C(1) << i)) + if (!BIT_SET(flags, i)) continue; r = strextendf_with_separator(&attrs, ",", "%u", i); diff --git a/src/shared/group-record.c b/src/shared/group-record.c index 7b401bf0644..4898616252c 100644 --- a/src/shared/group-record.c +++ b/src/shared/group-record.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "bitfield.h" #include "group-record.h" #include "json-util.h" #include "strv.h" @@ -334,7 +335,7 @@ int group_record_match(GroupRecord *h, const UserDBMatch *match) { if (h->gid < match->gid_min || h->gid > match->gid_max) return false; - if (!FLAGS_SET(match->disposition_mask, UINT64_C(1) << group_record_disposition(h))) + if (!BIT_SET(match->disposition_mask, group_record_disposition(h))) return false; if (!strv_isempty(match->fuzzy_names)) { diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index 4bd9fc65dd2..890d77dcc27 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -4,6 +4,7 @@ #include "alloc-util.h" #include "ansi-color.h" +#include "bitfield.h" #include "constants.h" #include "creds-util.h" #include "cryptsetup-util.h" @@ -6687,7 +6688,7 @@ int tpm2_pcr_prediction_to_json( _cleanup_(sd_json_variant_unrefp) sd_json_variant *vj = NULL; Tpm2PCRPredictionResult *banks; - if (!FLAGS_SET(prediction->pcrs, UINT32_C(1) << pcr)) + if (!BIT_SET(prediction->pcrs, pcr)) continue; ORDERED_SET_FOREACH(banks, prediction->results[pcr]) { @@ -6812,7 +6813,7 @@ int tpm2_calculate_policy_super_pcr( _cleanup_free_ Tpm2PCRValue *single_values = NULL; size_t n_single_values = 0; for (uint32_t pcr = 0; pcr < TPM2_PCRS_MAX; pcr++) { - if (!FLAGS_SET(prediction->pcrs, UINT32_C(1) << pcr)) + if (!BIT_SET(prediction->pcrs, pcr)) continue; if (ordered_set_size(prediction->results[pcr]) != 1) @@ -6848,7 +6849,7 @@ int tpm2_calculate_policy_super_pcr( size_t n_pcr_policy_digest_variants = 0; Tpm2PCRPredictionResult *banks; - if (!FLAGS_SET(prediction->pcrs, UINT32_C(1) << pcr)) + if (!BIT_SET(prediction->pcrs, pcr)) continue; if (ordered_set_size(prediction->results[pcr]) <= 1) /* We only care for PCRs with 2 or more variants in this loop */ @@ -6921,7 +6922,7 @@ int tpm2_policy_super_pcr( /* Look for all PCRs that have only a singled allowed hash value, and synthesize a single PolicyPCR policy item for them */ for (uint32_t pcr = 0; pcr < TPM2_PCRS_MAX; pcr++) { - if (!FLAGS_SET(prediction->pcrs, UINT32_C(1) << pcr)) + if (!BIT_SET(prediction->pcrs, pcr)) continue; if (ordered_set_size(prediction->results[pcr]) != 1) @@ -6951,7 +6952,7 @@ int tpm2_policy_super_pcr( for (uint32_t pcr = 0; pcr < TPM2_PCRS_MAX; pcr++) { size_t n_branches; - if (!FLAGS_SET(prediction->pcrs, UINT32_C(1) << pcr)) + if (!BIT_SET(prediction->pcrs, pcr)) continue; n_branches = ordered_set_size(prediction->results[pcr]); diff --git a/src/shared/user-record.c b/src/shared/user-record.c index 45577180236..131949a4e4f 100644 --- a/src/shared/user-record.c +++ b/src/shared/user-record.c @@ -2,6 +2,7 @@ #include +#include "bitfield.h" #include "cap-list.h" #include "cgroup-util.h" #include "dns-domain.h" @@ -2671,7 +2672,7 @@ int user_record_match(UserRecord *u, const UserDBMatch *match) { if (u->uid < match->uid_min || u->uid > match->uid_max) return false; - if (!FLAGS_SET(match->disposition_mask, UINT64_C(1) << user_record_disposition(u))) + if (!BIT_SET(match->disposition_mask, user_record_disposition(u))) return false; if (!strv_isempty(match->fuzzy_names)) { diff --git a/src/shared/vpick.c b/src/shared/vpick.c index 4720e7448d8..c2ca800af5b 100644 --- a/src/shared/vpick.c +++ b/src/shared/vpick.c @@ -3,6 +3,7 @@ #include #include "architecture.h" +#include "bitfield.h" #include "chase.h" #include "fd-util.h" #include "fs-util.h" @@ -108,7 +109,7 @@ static int errno_from_mode(uint32_t type_mask, mode_t found) { if (type_mask == 0) /* type doesn't matter */ return 0; - if (FLAGS_SET(type_mask, UINT32_C(1) << IFTODT(found))) + if (BIT_SET(type_mask, IFTODT(found))) return 0; if (type_mask == (UINT32_C(1) << DT_BLK)) @@ -164,7 +165,7 @@ static int pin_choice( return log_debug_errno(errno, "Failed to stat discovered inode '%s': %m", prefix_roota(toplevel_path, inode_path)); if (filter->type_mask != 0 && - !FLAGS_SET(filter->type_mask, UINT32_C(1) << IFTODT(st.st_mode))) + !BIT_SET(filter->type_mask, IFTODT(st.st_mode))) return log_debug_errno( SYNTHETIC_ERRNO(errno_from_mode(filter->type_mask, st.st_mode)), "Inode '%s' has wrong type, found '%s'.", @@ -596,7 +597,7 @@ int path_pick( filter_type_mask = filter->type_mask; if (slash_suffix) { /* If the pattern is suffixed by a / then we are looking for directories apparently. */ - if (filter_type_mask != 0 && !FLAGS_SET(filter_type_mask, UINT32_C(1) << DT_DIR)) + if (filter_type_mask != 0 && !BIT_SET(filter_type_mask, DT_DIR)) return log_debug_errno(SYNTHETIC_ERRNO(errno_from_mode(filter_type_mask, S_IFDIR)), "Specified pattern ends in '/', but not looking for directories, refusing."); filter_type_mask = UINT32_C(1) << DT_DIR; diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index bff05cda6f0..4c14031b0bc 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -19,6 +19,7 @@ #include "acl-util.h" #include "alloc-util.h" +#include "bitfield.h" #include "btrfs-util.h" #include "build.h" #include "capability-util.h" @@ -3120,7 +3121,7 @@ static char *age_by_to_string(AgeBy ab, bool is_dir) { return NULL; for (size_t i = 0; i < ELEMENTSOF(ab_map); i++) - if (FLAGS_SET(ab, 1U << i)) + if (BIT_SET(ab, i)) ret[j++] = is_dir ? ascii_toupper(ab_map[i]) : ab_map[i]; ret[j] = 0; diff --git a/src/udev/udev-builtin.c b/src/udev/udev-builtin.c index b47ca37d55b..b190504a831 100644 --- a/src/udev/udev-builtin.c +++ b/src/udev/udev-builtin.c @@ -3,6 +3,7 @@ #include #include +#include "bitfield.h" #include "device-private.h" #include "device-util.h" #include "string-util.h" @@ -57,7 +58,7 @@ UdevReloadFlags udev_builtin_should_reload(void) { void udev_builtin_reload(UdevReloadFlags flags) { for (UdevBuiltinCommand i = 0; i < _UDEV_BUILTIN_MAX; i++) { - if (!FLAGS_SET(flags, 1u << i) || !builtins[i]) + if (!BIT_SET(flags, i) || !builtins[i]) continue; if (builtins[i]->exit) builtins[i]->exit(); diff --git a/src/userdb/userdbctl.c b/src/userdb/userdbctl.c index 1ddd05789f9..a803df8b0b5 100644 --- a/src/userdb/userdbctl.c +++ b/src/userdb/userdbctl.c @@ -2,6 +2,7 @@ #include +#include "bitfield.h" #include "build.h" #include "dirent-util.h" #include "errno-list.h" @@ -194,7 +195,7 @@ static int table_add_uid_boundaries(Table *table, const UIDRange *p) { FOREACH_ELEMENT(i, uid_range_table) { _cleanup_free_ char *name = NULL, *comment = NULL; - if (!FLAGS_SET(arg_disposition_mask, UINT64_C(1) << i->disposition)) + if (!BIT_SET(arg_disposition_mask, i->disposition)) continue; if (!uid_range_covers(p, i->first, i->last - i->first + 1)) @@ -585,7 +586,7 @@ static int table_add_gid_boundaries(Table *table, const UIDRange *p) { FOREACH_ELEMENT(i, uid_range_table) { _cleanup_free_ char *name = NULL, *comment = NULL; - if (!FLAGS_SET(arg_disposition_mask, UINT64_C(1) << i->disposition)) + if (!BIT_SET(arg_disposition_mask, i->disposition)) continue; if (!uid_range_covers(p, i->first, i->last - i->first + 1))