当前位置: 首页>>代码示例>>C++>>正文


C++ ELEMENTSOF函数代码示例

本文整理汇总了C++中ELEMENTSOF函数的典型用法代码示例。如果您正苦于以下问题:C++ ELEMENTSOF函数的具体用法?C++ ELEMENTSOF怎么用?C++ ELEMENTSOF使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ELEMENTSOF函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mount_point_is_api

bool mount_point_is_api(const char *path) {
    unsigned i;

    /* Checks if this mount point is considered "API", and hence
     * should be ignored */

    for (i = 0; i < ELEMENTSOF(mount_table); i ++)
        if (path_equal(path, mount_table[i].where))
            return true;

    return path_startswith(path, "/sys/fs/cgroup/");
}
开发者ID:kyoiora,项目名称:systemd,代码行数:12,代码来源:mount-setup.c

示例2: create_dirs

static int create_dirs(const char *esp_path) {
        int r;
        unsigned i;

        for (i = 0; i < ELEMENTSOF(efi_subdirs); i++) {
                r = mkdir_one(esp_path, efi_subdirs[i]);
                if (r < 0)
                        return r;
        }

        return 0;
}
开发者ID:ChALkeR,项目名称:systemd,代码行数:12,代码来源:bootctl.c

示例3: adm_help

static int adm_help(struct udev *udev, int argc, char *argv[]) {
        unsigned int i;

        printf("%s [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS]\n\n"
               "Send control commands or test the device manager.\n\n"
               "Commands:\n"
               , program_invocation_short_name);

        for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++)
                if (udevadm_cmds[i]->help != NULL)
                        printf("  %-12s  %s\n", udevadm_cmds[i]->name, udevadm_cmds[i]->help);
        return 0;
}
开发者ID:OpenDZ,项目名称:systemd,代码行数:13,代码来源:udevadm.c

示例4: catalog_compare_func

int catalog_compare_func(const void *a, const void *b) {
        const CatalogItem *i = a, *j = b;
        unsigned k;

        for (k = 0; k < ELEMENTSOF(j->id.bytes); k++) {
                 if (i->id.bytes[k] < j->id.bytes[k])
                        return -1;
                 if (i->id.bytes[k] > j->id.bytes[k])
                        return 1;
        }

        return strcmp(i->language, j->language);
}
开发者ID:systemdiet,项目名称:systemdiet,代码行数:13,代码来源:catalog.c

示例5: test_prefixes_cb

static void test_prefixes_cb(sd_icmp6_nd *nd, int event, void *userdata) {
        sd_event *e = userdata;
        struct {
                struct in6_addr addr;
                uint8_t prefixlen;
                bool success;
        } addrs[] = {
                { { { { 0x20, 0x01, 0x0d, 0xb8, 0xde, 0xad, 0xbe, 0xef,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
                  63, true },
                { { { { 0x20, 0x01, 0x0d, 0xb8, 0xde, 0xad, 0x0d, 0xad,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
                  64, false },
                { { { { 0x20, 0x01, 0x0d, 0xb8, 0x0b, 0x16, 0xd0, 0x0d,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
                  60, true },
                { { { { 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x9d, 0xab, 0xcd,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
                  64, true },
                { { { { 0x20, 0x01, 0x0d, 0xb8, 0xde, 0xad, 0xbe, 0xed,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } } },
                  63, false },
        };
        uint8_t prefixlen;
        unsigned int i;

        for (i = 0; i < ELEMENTSOF(addrs); i++) {
                printf("  %s prefix %02x%02x:%02x%02x:%02x%02x:%02x%02x",
                        __FUNCTION__,
                        addrs[i].addr.s6_addr[0], addrs[i].addr.s6_addr[1],
                        addrs[i].addr.s6_addr[2], addrs[i].addr.s6_addr[3],
                        addrs[i].addr.s6_addr[4], addrs[i].addr.s6_addr[5],
                        addrs[i].addr.s6_addr[6], addrs[i].addr.s6_addr[7]);

                if (addrs[i].success) {
                        assert_se(sd_icmp6_ra_get_prefixlen(nd, &addrs[i].addr,
                                                                &prefixlen) >= 0);
                        assert_se(addrs[i].prefixlen == prefixlen);
                        printf("/%d onlink\n", prefixlen);
                } else {
                        assert_se(sd_icmp6_ra_get_prefixlen(nd, &addrs[i].addr,
                                                                &prefixlen) == -EADDRNOTAVAIL);
                        printf("/128 offlink\n");
                }
        }

        send_ra_function = send_ra_short_prefix;
        assert_se(sd_icmp6_nd_set_callback(nd, test_short_prefix_cb, e) >= 0);
        assert_se(sd_icmp6_nd_stop(nd) >= 0);
        assert_se(sd_icmp6_router_solicitation_start(nd) >= 0);
}
开发者ID:AlexBaranosky,项目名称:systemd,代码行数:51,代码来源:test-icmp6-rs.c

示例6: udev_builtin_lookup

enum udev_builtin_cmd udev_builtin_lookup(const char *command) {
        char name[UTIL_PATH_SIZE];
        enum udev_builtin_cmd i;
        char *pos;

        strscpy(name, sizeof(name), command);
        pos = strchr(name, ' ');
        if (pos)
                pos[0] = '\0';
        for (i = 0; i < ELEMENTSOF(builtins); i++)
                if (builtins[i] && streq(builtins[i]->name, name))
                        return i;
        return UDEV_BUILTIN_MAX;
}
开发者ID:OpenDZ,项目名称:systemd,代码行数:14,代码来源:udev-builtin.c

示例7: kmod_setup

int kmod_setup(void) {
        unsigned i;
        struct kmod_ctx *ctx = NULL;
        struct kmod_module *mod;
        int err;

        for (i = 0; i < ELEMENTSOF(kmod_table); i += 2) {

                if (access(kmod_table[i+1], F_OK) >= 0)
                        continue;

                log_debug("Your kernel apparently lacks built-in %s support. Might be a good idea to compile it in. "
                          "We'll now try to work around this by loading the module...",
                          kmod_table[i]);

                if (!ctx) {
                        ctx = kmod_new(NULL, NULL);
                        if (!ctx) {
                                log_error("Failed to allocate memory for kmod");
                                return -ENOMEM;
                        }

                        kmod_set_log_fn(ctx, systemd_kmod_log, NULL);

                        kmod_load_resources(ctx);
                }

                err = kmod_module_new_from_name(ctx, kmod_table[i], &mod);
                if (err < 0) {
                        log_error("Failed to load module '%s'", kmod_table[i]);
                        continue;
                }

                err = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL, NULL);
                if (err == 0)
                        log_info("Inserted module '%s'", kmod_module_get_name(mod));
                else if (err == KMOD_PROBE_APPLY_BLACKLIST)
                        log_info("Module '%s' is blacklisted", kmod_module_get_name(mod));
                else
                        log_error("Failed to insert '%s'", kmod_module_get_name(mod));

                kmod_module_unref(mod);
        }

        if (ctx)
                kmod_unref(ctx);

        return 0;
}
开发者ID:adsr,项目名称:systemd,代码行数:49,代码来源:kmod-setup.c

示例8: get_current_runlevel

static int get_current_runlevel(Context *c) {
        static const struct {
                const int runlevel;
                const char *special;
        } table[] = {
                /* The first target of this list that is active or has
                 * a job scheduled wins. We prefer runlevels 5 and 3
                 * here over the others, since these are the main
                 * runlevels used on Fedora. It might make sense to
                 * change the order on some distributions. */
                { '5', SPECIAL_RUNLEVEL5_TARGET },
                { '3', SPECIAL_RUNLEVEL3_TARGET },
                { '4', SPECIAL_RUNLEVEL4_TARGET },
                { '2', SPECIAL_RUNLEVEL2_TARGET },
                { '1', SPECIAL_RESCUE_TARGET },
        };

        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
        int r;
        unsigned i;

        assert(c);

        for (i = 0; i < ELEMENTSOF(table); i++) {
                _cleanup_free_ char *state = NULL, *path = NULL;

                path = unit_dbus_path_from_name(table[i].special);
                if (!path)
                        return log_oom();

                r = sd_bus_get_property_string(
                                c->bus,
                                "org.freedesktop.systemd1",
                                path,
                                "org.freedesktop.systemd1.Unit",
                                "ActiveState",
                                &error,
                                &state);
                if (r < 0) {
                        log_warning("Failed to get state: %s", bus_error_message(&error, -r));
                        return r;
                }

                if (streq(state, "active") || streq(state, "reloading"))
                        return table[i].runlevel;
        }

        return 0;
}
开发者ID:275288698,项目名称:systemd-ubuntu-with-dbus,代码行数:49,代码来源:update-utmp.c

示例9: test_hashmap_free_with_destructor

static void test_hashmap_free_with_destructor(void) {
        Hashmap *m;
        struct Item items[4] = {};
        unsigned i;

        assert_se(m = hashmap_new(NULL));
        for (i = 0; i < ELEMENTSOF(items) - 1; i++)
                assert_se(hashmap_put(m, INT_TO_PTR(i), items + i) == 1);

        m = hashmap_free_with_destructor(m, item_seen);
        assert_se(items[0].seen == 1);
        assert_se(items[1].seen == 1);
        assert_se(items[2].seen == 1);
        assert_se(items[3].seen == 0);
}
开发者ID:floppym,项目名称:systemd,代码行数:15,代码来源:test-hashmap.c

示例10: extract_multiplier

static char* extract_multiplier(char *p, usec_t *multiplier) {
        static const struct {
                const char *suffix;
                usec_t usec;
        } table[] = {
                { "seconds", USEC_PER_SEC    },
                { "second",  USEC_PER_SEC    },
                { "sec",     USEC_PER_SEC    },
                { "s",       USEC_PER_SEC    },
                { "minutes", USEC_PER_MINUTE },
                { "minute",  USEC_PER_MINUTE },
                { "min",     USEC_PER_MINUTE },
                { "months",  USEC_PER_MONTH  },
                { "month",   USEC_PER_MONTH  },
                { "M",       USEC_PER_MONTH  },
                { "msec",    USEC_PER_MSEC   },
                { "ms",      USEC_PER_MSEC   },
                { "m",       USEC_PER_MINUTE },
                { "hours",   USEC_PER_HOUR   },
                { "hour",    USEC_PER_HOUR   },
                { "hr",      USEC_PER_HOUR   },
                { "h",       USEC_PER_HOUR   },
                { "days",    USEC_PER_DAY    },
                { "day",     USEC_PER_DAY    },
                { "d",       USEC_PER_DAY    },
                { "weeks",   USEC_PER_WEEK   },
                { "week",    USEC_PER_WEEK   },
                { "w",       USEC_PER_WEEK   },
                { "years",   USEC_PER_YEAR   },
                { "year",    USEC_PER_YEAR   },
                { "y",       USEC_PER_YEAR   },
                { "usec",    1ULL            },
                { "us",      1ULL            },
        };
        unsigned i;

        for (i = 0; i < ELEMENTSOF(table); i++) {
                char *e;

                e = startswith(p, table[i].suffix);
                if (e) {
                        *multiplier = table[i].usec;
                        return e;
                }
        }

        return p;
}
开发者ID:GalliumOS,项目名称:network-manager,代码行数:48,代码来源:time-util.c

示例11: format_weekdays

static void format_weekdays(FILE *f, const CalendarSpec *c) {
        static const char *const days[] = {
                "Mon",
                "Tue",
                "Wed",
                "Thu",
                "Fri",
                "Sat",
                "Sun"
        };

        int l, x;
        bool need_colon = false;

        assert(f);
        assert(c);
        assert(c->weekdays_bits > 0 && c->weekdays_bits <= 127);

        for (x = 0, l = -1; x < (int) ELEMENTSOF(days); x++) {

                if (c->weekdays_bits & (1 << x)) {

                        if (l < 0) {
                                if (need_colon)
                                        fputc(',', f);
                                else
                                        need_colon = true;

                                fputs(days[x], f);
                                l = x;
                        }

                } else if (l >= 0) {

                        if (x > l + 1) {
                                fputc(x > l + 2 ? '-' : ',', f);
                                fputs(days[x-1], f);
                        }

                        l = -1;
                }
        }

        if (l >= 0 && x > l + 1) {
                fputc(x > l + 2 ? '-' : ',', f);
                fputs(days[x-1], f);
        }
}
开发者ID:RoadRunnr,项目名称:systemd,代码行数:48,代码来源:calendarspec.c

示例12: output_short

static int output_short(
                FILE *f,
                sd_journal *j,
                OutputMode mode,
                unsigned n_columns,
                OutputFlags flags,
                Set *output_fields,
                const size_t highlight[2]) {

        int r;
        const void *data;
        size_t length;
        size_t n = 0;
        _cleanup_free_ char *hostname = NULL, *identifier = NULL, *comm = NULL, *pid = NULL, *fake_pid = NULL, *message = NULL, *realtime = NULL, *monotonic = NULL, *priority = NULL, *unit = NULL, *user_unit = NULL;
        size_t hostname_len = 0, identifier_len = 0, comm_len = 0, pid_len = 0, fake_pid_len = 0, message_len = 0, realtime_len = 0, monotonic_len = 0, priority_len = 0, unit_len = 0, user_unit_len = 0;
        int p = LOG_INFO;
        bool ellipsized = false;
        const ParseFieldVec fields[] = {
                PARSE_FIELD_VEC_ENTRY("_PID=", &pid, &pid_len),
                PARSE_FIELD_VEC_ENTRY("_COMM=", &comm, &comm_len),
                PARSE_FIELD_VEC_ENTRY("MESSAGE=", &message, &message_len),
                PARSE_FIELD_VEC_ENTRY("PRIORITY=", &priority, &priority_len),
                PARSE_FIELD_VEC_ENTRY("_HOSTNAME=", &hostname, &hostname_len),
                PARSE_FIELD_VEC_ENTRY("SYSLOG_PID=", &fake_pid, &fake_pid_len),
                PARSE_FIELD_VEC_ENTRY("SYSLOG_IDENTIFIER=", &identifier, &identifier_len),
                PARSE_FIELD_VEC_ENTRY("_SOURCE_REALTIME_TIMESTAMP=", &realtime, &realtime_len),
                PARSE_FIELD_VEC_ENTRY("_SOURCE_MONOTONIC_TIMESTAMP=", &monotonic, &monotonic_len),
                PARSE_FIELD_VEC_ENTRY("_SYSTEMD_UNIT=", &unit, &unit_len),
                PARSE_FIELD_VEC_ENTRY("_SYSTEMD_USER_UNIT=", &user_unit, &user_unit_len),
        };
        size_t highlight_shifted[] = {highlight ? highlight[0] : 0, highlight ? highlight[1] : 0};

        assert(f);
        assert(j);

        /* Set the threshold to one bigger than the actual print
         * threshold, so that if the line is actually longer than what
         * we're willing to print, ellipsization will occur. This way
         * we won't output a misleading line without any indication of
         * truncation.
         */
        sd_journal_set_data_threshold(j, flags & (OUTPUT_SHOW_ALL|OUTPUT_FULL_WIDTH) ? 0 : PRINT_CHAR_THRESHOLD + 1);

        JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
                r = parse_fieldv(data, length, fields, ELEMENTSOF(fields));
                if (r < 0)
                        return r;
        }
开发者ID:floppym,项目名称:systemd,代码行数:48,代码来源:logs-show.c

示例13: main

int main(int argc, char *argv[])
{
        unsigned int i;

        test_invalid_buffer_length();
        test_cookie();

        test_options(NULL);

        for (i = 0; i < ELEMENTSOF(option_tests); i++)
                test_options(&option_tests[i]);

        test_option_set();

        return 0;
}
开发者ID:MOBO-OSS,项目名称:systemd-relative,代码行数:16,代码来源:test-dhcp-option.c

示例14: main

int main(int argc, const char *argv[]) {

        unsigned int i;

        for (i = 0; i < ELEMENTSOF(af_names); i++) {
                if (af_names[i]) {
                        assert_se(streq(af_to_name(i), af_names[i]));
                        assert_se(af_from_name(af_names[i]) == (int) i);
                }
        }

        assert_se(af_to_name(af_max()) == NULL);
        assert_se(af_to_name(-1) == NULL);
        assert_se(af_from_name("huddlduddl") == AF_UNSPEC);

        return 0;
}
开发者ID:abbradar,项目名称:systemd,代码行数:17,代码来源:test-af-list.c

示例15: skip_attribute

static bool skip_attribute(const char *name) {
        static const char* const skip[] = {
                "uevent",
                "dev",
                "modalias",
                "resource",
                "driver",
                "subsystem",
                "module",
        };
        unsigned int i;

        for (i = 0; i < ELEMENTSOF(skip); i++)
                if (streq(name, skip[i]))
                        return true;
        return false;
}
开发者ID:martinpitt,项目名称:systemd,代码行数:17,代码来源:udevadm-info.c


注:本文中的ELEMENTSOF函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。