您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ streq_ptr函数代码示例

51自学网 2021-06-03 08:29:35
  C++
这篇教程C++ streq_ptr函数代码示例写得很实用,希望能帮到您。

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

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

示例1: on_properties_changed

static int on_properties_changed(sd_bus_message *m, void *userdata, sd_bus_error *error) {        const char *name;        int r;        assert(m);        r = sd_bus_message_read(m, "s", &name);        if (r < 0)                return log_error_errno(r, "Failed to read interface name: %m");        if (!streq_ptr(name, "org.freedesktop.timesync1.Manager"))                return 0;        return show_timesync_status_once(sd_bus_message_get_bus(m));}
开发者ID:Keruspe,项目名称:systemd,代码行数:15,


示例2: test_unit_name_from_path_instance_one

static void test_unit_name_from_path_instance_one(const char *pattern, const char *path, const char *suffix, const char *expected, int ret) {        _cleanup_free_ char *t = NULL;        assert_se(unit_name_from_path_instance(pattern, path, suffix, &t) == ret);        puts(strna(t));        assert_se(streq_ptr(t, expected));        if (t) {                _cleanup_free_ char *k = NULL, *v = NULL;                assert_se(unit_name_to_instance(t, &k) > 0);                assert_se(unit_name_path_unescape(k, &v) == 0);                assert_se(path_equal(v, isempty(path) ? "/" : path));        }}
开发者ID:BenjaminLefoul,项目名称:systemd,代码行数:15,


示例3: same_entry

static bool same_entry(uint16_t id, const sd_id128_t uuid, const char *path) {        _cleanup_free_ char *opath = NULL;        sd_id128_t ouuid;        int r;        r = efi_get_boot_option(id, NULL, &ouuid, &opath, NULL);        if (r < 0)                return false;        if (!sd_id128_equal(uuid, ouuid))                return false;        if (!streq_ptr(path, opath))                return false;        return true;}
开发者ID:ChALkeR,项目名称:systemd,代码行数:15,


示例4: method_set_hostname

static int method_set_hostname(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {        Context *c = userdata;        const char *name;        int interactive;        char *h;        int r;        r = sd_bus_message_read(m, "sb", &name, &interactive);        if (r < 0)                return r;        if (isempty(name))                name = c->data[PROP_STATIC_HOSTNAME];        if (isempty(name))                name = "localhost";        if (!hostname_is_valid(name))                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid hostname '%s'", name);        if (streq_ptr(name, c->data[PROP_HOSTNAME]))                return sd_bus_reply_method_return(m, NULL);        r = bus_verify_polkit_async(m, CAP_SYS_ADMIN, "org.freedesktop.hostname1.set-hostname", interactive, &c->polkit_registry, error);        if (r < 0)                return r;        if (r == 0)                return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */        h = strdup(name);        if (!h)                return -ENOMEM;        free(c->data[PROP_HOSTNAME]);        c->data[PROP_HOSTNAME] = h;        r = context_update_kernel_hostname(c);        if (r < 0) {                log_error_errno(r, "Failed to set host name: %m");                return sd_bus_error_set_errnof(error, r, "Failed to set hostname: %s", strerror(-r));        }        log_info("Changed host name to '%s'", strna(c->data[PROP_HOSTNAME]));        sd_bus_emit_properties_changed(bus, "/org/freedesktop/hostname1", "org.freedesktop.hostname1", "Hostname", NULL);        return sd_bus_reply_method_return(m, NULL);}
开发者ID:pwaller,项目名称:systemd,代码行数:48,


示例5: test_get_group_creds_one

static void test_get_group_creds_one(const char *id, const char *name, gid_t gid) {        gid_t rgid = GID_INVALID;        int r;        log_info("/* %s(/"%s/", /"%s/", "GID_FMT") */", __func__, id, name, gid);        r = get_group_creds(&id, &rgid, 0);        log_info_errno(r, "got /"%s/", "GID_FMT": %m", id, rgid);        if (!synthesize_nobody() && streq(name, NOBODY_GROUP_NAME)) {                log_info("(skipping detailed tests because nobody is not synthesized)");                return;        }        assert_se(r == 0);        assert_se(streq_ptr(id, name));        assert_se(rgid == gid);}
开发者ID:floppym,项目名称:systemd,代码行数:16,


示例6: names_ccw

static int names_ccw(struct  udev_device *dev, struct netnames *names) {        struct udev_device *cdev;        const char *bus_id;        size_t bus_id_len;        int rc;        assert(dev);        assert(names);        /* Retrieve the associated CCW device */        cdev = udev_device_get_parent(dev);        if (!cdev)                return -ENOENT;        /* Network devices are always grouped CCW devices */        if (!streq_ptr("ccwgroup", udev_device_get_subsystem(cdev)))                return -ENOENT;        /* Retrieve bus-ID of the grouped CCW device.  The bus-ID uniquely         * identifies the network device on the Linux on System z channel         * subsystem.  Note that the bus-ID contains lowercase characters.         */        bus_id = udev_device_get_sysname(cdev);        if (!bus_id)                return -ENOENT;        /* Check the length of the bus-ID.  Rely on that the kernel provides         * a correct bus-ID; alternatively, improve this check and parse and         * verify each bus-ID part...         */        bus_id_len = strlen(bus_id);        if (!bus_id_len || bus_id_len < 8 || bus_id_len > 9)                return -EINVAL;        /* Strip leading zeros from the bus id for aesthetic purposes. This         * keeps the ccw names stable, yet much shorter in general case of         * bus_id 0.0.0600 -> 600. This is similar to e.g. how PCI domain is         * not prepended when it is zero.         */        bus_id += strspn(bus_id, ".0");        /* Store the CCW bus-ID for use as network device name */        rc = snprintf(names->ccw_group, sizeof(names->ccw_group), "c%s", bus_id);        if (rc >= 0 && rc < (int)sizeof(names->ccw_group))                names->type = NET_CCWGROUP;        return 0;}
开发者ID:BenjaminLefoul,项目名称:systemd,代码行数:47,


示例7: udev_builtin_hwdb_search

static int udev_builtin_hwdb_search(struct udev_device *dev, struct udev_device *srcdev,                                    const char *subsystem, const char *prefix,                                    const char *filter, bool test) {        struct udev_device *d;        char s[16];        bool last = false;        int r = 0;        assert(dev);        if (!srcdev)                srcdev = dev;        for (d = srcdev; d && !last; d = udev_device_get_parent(d)) {                const char *dsubsys;                const char *modalias = NULL;                dsubsys = udev_device_get_subsystem(d);                if (!dsubsys)                        continue;                /* look only at devices of a specific subsystem */                if (subsystem && !streq(dsubsys, subsystem))                        continue;                modalias = udev_device_get_property_value(d, "MODALIAS");                if (streq(dsubsys, "usb") && streq_ptr(udev_device_get_devtype(d), "usb_device")) {                        /* if the usb_device does not have a modalias, compose one */                        if (!modalias)                                modalias = modalias_usb(d, s, sizeof(s));                        /* avoid looking at any parent device, they are usually just a USB hub */                        last = true;                }                if (!modalias)                        continue;                r = udev_builtin_hwdb_lookup(dev, prefix, modalias, filter, test);                if (r > 0)                        break;        }        return r;}
开发者ID:jamespharvey20,项目名称:systemd,代码行数:46,


示例8: names_pci

static int names_pci(struct udev_device *dev, struct netnames *names) {        struct udev_device *parent;        parent = udev_device_get_parent(dev);        if (!parent)                return -ENOENT;        /* check if our direct parent is a PCI device with no other bus in-between */        if (streq_ptr("pci", udev_device_get_subsystem(parent))) {                names->type = NET_PCI;                names->pcidev = parent;        } else {                names->pcidev = udev_device_get_parent_with_subsystem_devtype(dev, "pci", NULL);                if (!names->pcidev)                        return -ENOENT;        }        dev_pci_onboard(dev, names);        dev_pci_slot(dev, names);        return 0;}
开发者ID:fest3er,项目名称:eudev,代码行数:19,


示例9: test_strv_split_extract

static void test_strv_split_extract(void) {        _cleanup_strv_free_ char **l = NULL;        const char *str = ":foo//:bar::waldo:";        int r;        r = strv_split_extract(&l, str, ":", EXTRACT_DONT_COALESCE_SEPARATORS);        assert_se(r == (int) strv_length(l));        assert_se(streq_ptr(l[0], ""));        assert_se(streq_ptr(l[1], "foo:bar"));        assert_se(streq_ptr(l[2], ""));        assert_se(streq_ptr(l[3], "waldo"));        assert_se(streq_ptr(l[4], ""));        assert_se(streq_ptr(l[5], NULL));}
开发者ID:Keruspe,项目名称:systemd,代码行数:14,


示例10: kbdctx_refresh_compose_table

static int kbdctx_refresh_compose_table(kbdctx *kc, const char *lang) {        kbdtbl *kt;        idev_session *s;        idev_device *d;        Iterator i, j;        int r;        if (!lang)                lang = "C";        if (streq_ptr(kc->locale_lang, lang))                return 0;        r = free_and_strdup(&kc->locale_lang, lang);        if (r < 0)                return r;        log_debug("idev-keyboard: new default compose table: [ %s ]", lang);        r = kbdtbl_new_from_locale(&kt, kc, lang);        if (r < 0) {                /* TODO: We need to catch the case where no compose-file is                 * available. xkb doesn't tell us so far.. so we must not treat                 * it as a hard-failure but just continue. Preferably, we want                 * xkb to tell us exactly whether compilation failed or whether                 * there is no compose file available for this locale. */                log_debug_errno(r, "idev-keyboard: cannot load compose-table for '%s': %m",                                lang);                r = 0;                kt = NULL;        }        kbdtbl_unref(kc->kbdtbl);        kc->kbdtbl = kt;        HASHMAP_FOREACH(s, kc->context->session_map, i)                HASHMAP_FOREACH(d, s->device_map, j)                        if (idev_is_keyboard(d))                                keyboard_update_kbdtbl(keyboard_from_device(d));        return 0;}
开发者ID:RaghavanSanthanam,项目名称:systemd,代码行数:42,


示例11: same_entry

static bool same_entry(uint16_t id, const sd_id128_t uuid, const char *path) {        char *opath = NULL;        sd_id128_t ouuid;        int err;        bool same = false;        err = efi_get_boot_option(id, NULL, &ouuid, &opath, NULL);        if (err < 0)                return false;        if (!sd_id128_equal(uuid, ouuid))                goto finish;        if (!streq_ptr(path, opath))                goto finish;        same = true;finish:        return same;}
开发者ID:RaghavanSanthanam,项目名称:systemd,代码行数:20,


示例12: names_ccw

static int names_ccw(struct  udev_device *dev, struct netnames *names) {        struct udev_device *cdev;        const char *bus_id;        size_t bus_id_len;        int rc;        assert(dev);        assert(names);        /* Retrieve the associated CCW device */        cdev = udev_device_get_parent(dev);        if (!cdev)                return -ENOENT;        /* Network devices are always grouped CCW devices */        if (!streq_ptr("ccwgroup", udev_device_get_subsystem(cdev)))                return -ENOENT;        /* Retrieve bus-ID of the grouped CCW device.  The bus-ID uniquely         * identifies the network device on the Linux on System z channel         * subsystem.  Note that the bus-ID contains lowercase characters.         */        bus_id = udev_device_get_sysname(cdev);        if (!bus_id)                return -ENOENT;        /* Check the length of the bus-ID.  Rely on that the kernel provides         * a correct bus-ID; alternatively, improve this check and parse and         * verify each bus-ID part...         */        bus_id_len = strlen(bus_id);        if (!bus_id_len || bus_id_len < 8 || bus_id_len > 9)                return -EINVAL;        /* Store the CCW bus-ID for use as network device name */        rc = snprintf(names->ccw_group, sizeof(names->ccw_group), "ccw%s", bus_id);        if (rc >= 0 && rc < (int)sizeof(names->ccw_group))                names->type = NET_CCWGROUP;        return 0;}
开发者ID:lnykryn,项目名称:systemd,代码行数:40,


示例13: manager_parse_server_string

int manager_parse_server_string(Manager *m, ServerType type, const char *string) {        ServerName *first;        int r;        assert(m);        assert(string);        first = type == SERVER_FALLBACK ? m->fallback_servers : m->system_servers;        if (type == SERVER_FALLBACK)                 m->have_fallbacks = true;        for (;;) {                _cleanup_free_ char *word = NULL;                bool found = false;                ServerName *n;                r = extract_first_word(&string, &word, NULL, 0);                if (r < 0)                        return log_error_errno(r, "Failed to parse timesyncd server syntax /"%s/": %m", string);                if (r == 0)                        break;                /* Filter out duplicates */                LIST_FOREACH(names, n, first)                        if (streq_ptr(n->string, word)) {                                found = true;                                break;                        }                if (found)                        continue;                r = server_name_new(m, NULL, type, word);                if (r < 0)                        return r;        }        return 0;}
开发者ID:OpenDZ,项目名称:systemd,代码行数:40,


示例14: test_get_user_creds_one

static void test_get_user_creds_one(const char *id, const char *name, uid_t uid, gid_t gid, const char *home, const char *shell) {        const char *rhome = NULL;        const char *rshell = NULL;        uid_t ruid = UID_INVALID;        gid_t rgid = GID_INVALID;        int r;        log_info("/* %s(/"%s/", /"%s/", "UID_FMT", "GID_FMT", /"%s/", /"%s/") */",                 __func__, id, name, uid, gid, home, shell);        r = get_user_creds(&id, &ruid, &rgid, &rhome, &rshell, 0);        log_info_errno(r, "got /"%s/", "UID_FMT", "GID_FMT", /"%s/", /"%s/": %m",                       id, ruid, rgid, strnull(rhome), strnull(rshell));        if (!synthesize_nobody() && streq(name, NOBODY_USER_NAME)) {                log_info("(skipping detailed tests because nobody is not synthesized)");                return;        }        assert_se(r == 0);        assert_se(streq_ptr(id, name));        assert_se(ruid == uid);        assert_se(rgid == gid);        assert_se(path_equal(rhome, home));        assert_se(path_equal(rshell, shell));}
开发者ID:floppym,项目名称:systemd,代码行数:24,


示例15: test_strextend_with_separator

static void test_strextend_with_separator(void) {        _cleanup_free_ char *str = NULL;        assert_se(strextend_with_separator(&str, NULL, NULL));        assert_se(streq_ptr(str, ""));        str = mfree(str);        assert_se(strextend_with_separator(&str, "...", NULL));        assert_se(streq_ptr(str, ""));        assert_se(strextend_with_separator(&str, "...", NULL));        assert_se(streq_ptr(str, ""));        str = mfree(str);        assert_se(strextend_with_separator(&str, "xyz", "a", "bb", "ccc", NULL));        assert_se(streq_ptr(str, "axyzbbxyzccc"));        str = mfree(str);        assert_se(strextend_with_separator(&str, ",", "start", "", "1", "234", NULL));        assert_se(streq_ptr(str, "start,,1,234"));        assert_se(strextend_with_separator(&str, ";", "more", "5", "678", NULL));        assert_se(streq_ptr(str, "start,,1,234;more;5;678"));}
开发者ID:davide125,项目名称:systemd,代码行数:22,


示例16: test_bus_path_encode_many

static void test_bus_path_encode_many(void) {        _cleanup_free_ char *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *f = NULL;        assert_se(sd_bus_path_decode_many("/foo/bar", "/prefix/%", NULL) == 0);        assert_se(sd_bus_path_decode_many("/prefix/bar", "/prefix/%bar", NULL) == 1);        assert_se(sd_bus_path_decode_many("/foo/bar", "/prefix/%/suffix", NULL) == 0);        assert_se(sd_bus_path_decode_many("/prefix/foobar/suffix", "/prefix/%/suffix", &a) == 1 && streq_ptr(a, "foobar"));        assert_se(sd_bus_path_decode_many("/prefix/one_foo_two/mid/three_bar_four/suffix", "/prefix/one_%_two/mid/three_%_four/suffix", &b, &c) == 1 && streq_ptr(b, "foo") && streq_ptr(c, "bar"));        assert_se(sd_bus_path_decode_many("/prefix/one_foo_two/mid/three_bar_four/suffix", "/prefix/one_%_two/mid/three_%_four/suffix", NULL, &d) == 1 && streq_ptr(d, "bar"));        assert_se(sd_bus_path_decode_many("/foo/bar", "/foo/bar/%", NULL) == 0);        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/foo/bar%", NULL) == 0);        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/foo/%/bar", NULL) == 0);        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/foo/%bar", NULL) == 0);        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/foo/bar/suffix") == 1);        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/foo/%%/suffix", NULL, NULL) == 0); /* multiple '%' are treated verbatim */        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/foo/%/suffi", NULL) == 0);        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/foo/%/suffix", &e) == 1 && streq_ptr(e, "bar"));        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/foo/%/%", NULL, NULL) == 1);        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/%/%/%", NULL, NULL, NULL) == 1);        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "%/%/%", NULL, NULL, NULL) == 0);        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/%/%", NULL, NULL) == 0);        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/%/%/", NULL, NULL) == 0);        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/%/", NULL) == 0);        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "/%", NULL) == 0);        assert_se(sd_bus_path_decode_many("/foo/bar/suffix", "%", NULL) == 0);        assert_se(sd_bus_path_encode_many(&f, "/prefix/one_%_two/mid/three_%_four/suffix", "foo", "bar") >= 0 && streq_ptr(f, "/prefix/one_foo_two/mid/three_bar_four/suffix"));}
开发者ID:arthur-c,项目名称:systemd,代码行数:29,


示例17: vconsole_convert_to_x11

int vconsole_convert_to_x11(Context *c) {        const char *map;        int modified = -1;        map = systemd_kbd_model_map();        if (isempty(c->vc_keymap)) {                modified =                        !isempty(c->x11_layout) ||                        !isempty(c->x11_model) ||                        !isempty(c->x11_variant) ||                        !isempty(c->x11_options);                context_free_x11(c);        } else {                _cleanup_fclose_ FILE *f = NULL;                unsigned n = 0;                f = fopen(map, "re");                if (!f)                        return -errno;                for (;;) {                        _cleanup_strv_free_ char **a = NULL;                        int r;                        r = read_next_mapping(map, 5, UINT_MAX, f, &n, &a);                        if (r < 0)                                return r;                        if (r == 0)                                break;                        if (!streq(c->vc_keymap, a[0]))                                continue;                        if (!streq_ptr(c->x11_layout, strnulldash(a[1])) ||                            !streq_ptr(c->x11_model, strnulldash(a[2])) ||                            !streq_ptr(c->x11_variant, strnulldash(a[3])) ||                            !streq_ptr(c->x11_options, strnulldash(a[4]))) {                                if (free_and_strdup(&c->x11_layout, strnulldash(a[1])) < 0 ||                                    free_and_strdup(&c->x11_model, strnulldash(a[2])) < 0 ||                                    free_and_strdup(&c->x11_variant, strnulldash(a[3])) < 0 ||                                    free_and_strdup(&c->x11_options, strnulldash(a[4])) < 0)                                        return -ENOMEM;                                modified = true;                        }                        break;                }        }        if (modified > 0)                log_info("Changing X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'",                         strempty(c->x11_layout),                         strempty(c->x11_model),                         strempty(c->x11_variant),                         strempty(c->x11_options));        else if (modified < 0)                log_notice("X11 keyboard layout was not modified: no conversion found for /"%s/".",                           c->vc_keymap);        else                log_debug("X11 keyboard layout did not need to be modified.");        return modified > 0;}
开发者ID:halfline,项目名称:systemd,代码行数:67,


示例18: test_streq_ptr

static void test_streq_ptr(void) {        assert_se(streq_ptr(NULL, NULL));        assert_se(!streq_ptr("abc", "cdef"));}
开发者ID:banada,项目名称:systemd,代码行数:4,


示例19: convert_x11_to_vconsole

static int convert_x11_to_vconsole(DBusConnection *connection) {        bool modified = false;        assert(connection);        if (isempty(state.x11_layout)) {                modified =                        !isempty(state.vc_keymap) ||                        !isempty(state.vc_keymap_toggle);                free_data_x11();        } else {                FILE *f;                unsigned n = 0;                unsigned best_matching = 0;                char *new_keymap = NULL;                f = fopen(SYSTEMD_KBD_MODEL_MAP, "re");                if (!f)                        return -errno;                for (;;) {                        char **a;                        unsigned matching = 0;                        int r;                        r = read_next_mapping(f, &n, &a);                        if (r < 0) {                                fclose(f);                                return r;                        }                        if (r == 0)                                break;                        /* Determine how well matching this entry is */                        if (streq_ptr(state.x11_layout, a[1]))                                /* If we got an exact match, this is best */                                matching = 10;                        else {                                size_t x;                                x = strcspn(state.x11_layout, ",");                                /* We have multiple X layouts, look                                 * for an entry that matches our key                                 * with the everything but the first                                 * layout stripped off. */                                if (x > 0 &&                                    strlen(a[1]) == x &&                                    strncmp(state.x11_layout, a[1], x) == 0)                                        matching = 5;                                else  {                                        size_t w;                                        /* If that didn't work, strip                                         * off the other layouts from                                         * the entry, too */                                        w = strcspn(a[1], ",");                                        if (x > 0 && x == w &&                                            memcmp(state.x11_layout, a[1], x) == 0)                                                matching = 1;                                }                        }                        if (matching > 0 &&                            streq_ptr(state.x11_model, a[2])) {                                matching++;                                if (streq_ptr(state.x11_variant, a[3])) {                                        matching++;                                        if (streq_ptr(state.x11_options, a[4]))                                                matching++;                                }                        }                        /* The best matching entry so far, then let's                         * save that */                        if (matching > best_matching) {                                best_matching = matching;                                free(new_keymap);                                new_keymap = strdup(a[0]);                                if (!new_keymap) {                                        strv_free(a);                                        fclose(f);                                        return -ENOMEM;                                }                        }                        strv_free(a);                }                fclose(f);//.........这里部分代码省略.........
开发者ID:mariux,项目名称:systemd,代码行数:101,


示例20: convert_vconsole_to_x11

static int convert_vconsole_to_x11(DBusConnection *connection) {        bool modified = false;        assert(connection);        if (isempty(state.vc_keymap)) {                modified =                        !isempty(state.x11_layout) ||                        !isempty(state.x11_model) ||                        !isempty(state.x11_variant) ||                        !isempty(state.x11_options);                free_data_x11();        } else {                FILE *f;                unsigned n = 0;                f = fopen(SYSTEMD_KBD_MODEL_MAP, "re");                if (!f)                        return -errno;                for (;;) {                        char **a;                        int r;                        r = read_next_mapping(f, &n, &a);                        if (r < 0) {                                fclose(f);                                return r;                        }                        if (r == 0)                                break;                        if (!streq(state.vc_keymap, a[0])) {                                strv_free(a);                                continue;                        }                        if (!streq_ptr(state.x11_layout, strnulldash(a[1])) ||                            !streq_ptr(state.x11_model, strnulldash(a[2])) ||                            !streq_ptr(state.x11_variant, strnulldash(a[3])) ||                            !streq_ptr(state.x11_options, strnulldash(a[4]))) {                                if (free_and_set(&state.x11_layout, strnulldash(a[1])) < 0 ||                                    free_and_set(&state.x11_model, strnulldash(a[2])) < 0 ||                                    free_and_set(&state.x11_variant, strnulldash(a[3])) < 0 ||                                    free_and_set(&state.x11_options, strnulldash(a[4])) < 0) {                                        strv_free(a);                                        fclose(f);                                        return -ENOMEM;                                }                                modified = true;                        }                        strv_free(a);                        break;                }                fclose(f);        }        if (modified) {                dbus_bool_t b;                DBusMessage *changed;                int r;                r = write_data_x11();                if (r < 0)                        log_error("Failed to set X11 keyboard layout: %s", strerror(-r));                changed = bus_properties_changed_new(                                "/org/freedesktop/locale1",                                "org.freedesktop.locale1",                                "X11Layout/0"                                "X11Model/0"                                "X11Variant/0"                                "X11Options/0");                if (!changed)                        return -ENOMEM;                b = dbus_connection_send(connection, changed, NULL);                dbus_message_unref(changed);                if (!b)                        return -ENOMEM;        }        return 0;}
开发者ID:mariux,项目名称:systemd,代码行数:93,


示例21: locale_message_handler

static DBusHandlerResult locale_message_handler(                DBusConnection *connection,                DBusMessage *message,                void *userdata) {        DBusMessage *reply = NULL, *changed = NULL;        DBusError error;        int r;        assert(connection);        assert(message);        dbus_error_init(&error);        if (dbus_message_is_method_call(message, "org.freedesktop.locale1", "SetLocale")) {                char **l = NULL, **i;                dbus_bool_t interactive;                DBusMessageIter iter;                bool modified = false;                bool passed[_PROP_MAX];                int p;                if (!dbus_message_iter_init(message, &iter))                        return bus_send_error_reply(connection, message, NULL, -EINVAL);                r = bus_parse_strv_iter(&iter, &l);                if (r < 0) {                        if (r == -ENOMEM)                                goto oom;                        return bus_send_error_reply(connection, message, NULL, r);                }                if (!dbus_message_iter_next(&iter) ||                    dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN)  {                        strv_free(l);                        return bus_send_error_reply(connection, message, NULL, -EINVAL);                }                dbus_message_iter_get_basic(&iter, &interactive);                zero(passed);                /* Check whether a variable changed and if so valid */                STRV_FOREACH(i, l) {                        bool valid = false;                        for (p = 0; p < _PROP_MAX; p++) {                                size_t k;                                k = strlen(names[p]);                                if (startswith(*i, names[p]) && (*i)[k] == '=') {                                        valid = true;                                        passed[p] = true;                                        if (!streq_ptr(*i + k + 1, data[p]))                                                modified = true;                                        break;                                }                        }                        if (!valid) {                                strv_free(l);                                return bus_send_error_reply(connection, message, NULL, -EINVAL);                        }                }
开发者ID:mariux,项目名称:systemd,代码行数:67,


示例22: main

//.........这里部分代码省略.........        assert_se(r >= 0);        assert_se(sz == STRING_SIZE);        r = sd_bus_message_append_string_memfd(m, f, 0, (uint64_t) -1);        assert_se(r >= 0);        close(f);        f = memfd_new_and_map(NULL, SECOND_ARRAY, (void**) &p);        assert_se(f >= 0);        p[0] = '<';        memset(p+1, 'P', SECOND_ARRAY-2);        p[SECOND_ARRAY-1] = '>';        munmap(p, SECOND_ARRAY);        r = memfd_get_size(f, &sz);        assert_se(r >= 0);        assert_se(sz == SECOND_ARRAY);        r = sd_bus_message_append_array_memfd(m, 'y', f, 0, (uint64_t) -1);        assert_se(r >= 0);        close(f);        r = sd_bus_message_close_container(m);        assert_se(r >= 0);        r = sd_bus_message_append(m, "u", 4711);        assert_se(r >= 0);        assert_se((sfd = memfd_new_and_map(NULL, 6, (void**) &p)) >= 0);        memcpy(p, "abcd/0", 6);        munmap(p, 6);        assert_se(sd_bus_message_append_string_memfd(m, sfd, 1, 4) >= 0);        r = bus_message_seal(m, 55, 99*USEC_PER_SEC);        assert_se(r >= 0);        bus_message_dump(m, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);        r = sd_bus_send(b, m, NULL);        assert_se(r >= 0);        sd_bus_message_unref(m);        r = sd_bus_process(a, &m);        assert_se(r > 0);        bus_message_dump(m, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);        sd_bus_message_rewind(m, true);        r = sd_bus_message_enter_container(m, 'r', "aysay");        assert_se(r > 0);        r = sd_bus_message_read_array(m, 'y', (const void**) &p, &l);        assert_se(r > 0);        assert_se(l == FIRST_ARRAY);        assert_se(p[0] == '<');        for (i = 1; i < l-1; i++)                assert_se(p[i] == 'L');        assert_se(p[l-1] == '>');        r = sd_bus_message_read(m, "s", &s);        assert_se(r > 0);        assert_se(s[0] == '<');        for (i = 1; i < STRING_SIZE-2; i++)                assert_se(s[i] == (char) ('0' + (i % 10)));        assert_se(s[STRING_SIZE-2] == '>');        assert_se(s[STRING_SIZE-1] == 0);        r = sd_bus_message_read_array(m, 'y', (const void**) &p, &l);        assert_se(r > 0);        assert_se(l == SECOND_ARRAY);        assert_se(p[0] == '<');        for (i = 1; i < l-1; i++)                assert_se(p[i] == 'P');        assert_se(p[l-1] == '>');        r = sd_bus_message_exit_container(m);        assert_se(r > 0);        r = sd_bus_message_read(m, "u", &u32);        assert_se(r > 0);        assert_se(u32 == 4711);        r = sd_bus_message_read(m, "s", &s);        assert_se(r > 0);        assert_se(streq_ptr(s, "bcd"));        sd_bus_message_unref(m);        sd_bus_unref(a);        sd_bus_unref(b);        return 0;}
开发者ID:AlexBaranosky,项目名称:systemd,代码行数:101,


示例23: _nss_myhostname_gethostbyname4_r

enum nss_status _nss_myhostname_gethostbyname4_r(                const char *name,                struct gaih_addrtuple **pat,                char *buffer, size_t buflen,                int *errnop, int *h_errnop,                int32_t *ttlp) {        struct gaih_addrtuple *r_tuple, *r_tuple_prev = NULL;        _cleanup_free_ struct local_address *addresses = NULL;        _cleanup_free_ char *hn = NULL;        const char *canonical = NULL;        int n_addresses = 0, lo_ifi;        uint32_t local_address_ipv4;        struct local_address *a;        size_t l, idx, ms;        char *r_name;        unsigned n;        assert(name);        assert(pat);        assert(buffer);        assert(errnop);        assert(h_errnop);        if (is_localhost(name)) {                /* We respond to 'localhost', so that /etc/hosts                 * is optional */                canonical = "localhost";                local_address_ipv4 = htonl(INADDR_LOOPBACK);        } else if (is_gateway_hostname(name)) {                n_addresses = local_gateways(NULL, 0, AF_UNSPEC, &addresses);                if (n_addresses <= 0) {                        *errnop = ENOENT;                        *h_errnop = HOST_NOT_FOUND;                        return NSS_STATUS_NOTFOUND;                }                canonical = "gateway";        } else {                hn = gethostname_malloc();                if (!hn) {                        *errnop = ENOMEM;                        *h_errnop = NO_RECOVERY;                        return NSS_STATUS_TRYAGAIN;                }                /* We respond to our local host name, our our hostname suffixed with a single dot. */                if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) {                        *errnop = ENOENT;                        *h_errnop = HOST_NOT_FOUND;                        return NSS_STATUS_NOTFOUND;                }                n_addresses = local_addresses(NULL, 0, AF_UNSPEC, &addresses);                if (n_addresses < 0)                        n_addresses = 0;                canonical = hn;                local_address_ipv4 = LOCALADDRESS_IPV4;        }        /* If this call fails we fill in 0 as scope. Which is fine */        lo_ifi = n_addresses <= 0 ? LOOPBACK_IFINDEX : 0;        l = strlen(canonical);        ms = ALIGN(l+1) + ALIGN(sizeof(struct gaih_addrtuple)) * (n_addresses > 0 ? n_addresses : 2);        if (buflen < ms) {                *errnop = ENOMEM;                *h_errnop = NO_RECOVERY;                return NSS_STATUS_TRYAGAIN;        }        /* First, fill in hostname */        r_name = buffer;        memcpy(r_name, canonical, l+1);        idx = ALIGN(l+1);        if (n_addresses <= 0) {                /* Second, fill in IPv6 tuple */                r_tuple = (struct gaih_addrtuple*) (buffer + idx);                r_tuple->next = r_tuple_prev;                r_tuple->name = r_name;                r_tuple->family = AF_INET6;                memcpy(r_tuple->addr, LOCALADDRESS_IPV6, 16);                r_tuple->scopeid = (uint32_t) lo_ifi;                idx += ALIGN(sizeof(struct gaih_addrtuple));                r_tuple_prev = r_tuple;                /* Third, fill in IPv4 tuple */                r_tuple = (struct gaih_addrtuple*) (buffer + idx);                r_tuple->next = r_tuple_prev;                r_tuple->name = r_name;                r_tuple->family = AF_INET;                *(uint32_t*) r_tuple->addr = local_address_ipv4;                r_tuple->scopeid = (uint32_t) lo_ifi;//.........这里部分代码省略.........
开发者ID:abbradar,项目名称:systemd,代码行数:101,


示例24: vconsole_convert_to_x11

static int vconsole_convert_to_x11(Context *c, sd_bus *bus) {        bool modified = false;        assert(bus);        if (isempty(c->vc_keymap)) {                modified =                        !isempty(c->x11_layout) ||                        !isempty(c->x11_model) ||                        !isempty(c->x11_variant) ||                        !isempty(c->x11_options);                context_free_x11(c);        } else {                _cleanup_fclose_ FILE *f = NULL;                unsigned n = 0;                f = fopen(SYSTEMD_KBD_MODEL_MAP, "re");                if (!f)                        return -errno;                for (;;) {                        _cleanup_strv_free_ char **a = NULL;                        int r;                        r = read_next_mapping(f, &n, &a);                        if (r < 0)                                return r;                        if (r == 0)                                break;                        if (!streq(c->vc_keymap, a[0]))                                continue;                        if (!streq_ptr(c->x11_layout, strnulldash(a[1])) ||                            !streq_ptr(c->x11_model, strnulldash(a[2])) ||                            !streq_ptr(c->x11_variant, strnulldash(a[3])) ||                            !streq_ptr(c->x11_options, strnulldash(a[4]))) {                                if (free_and_strdup(&c->x11_layout, strnulldash(a[1])) < 0 ||                                    free_and_strdup(&c->x11_model, strnulldash(a[2])) < 0 ||                                    free_and_strdup(&c->x11_variant, strnulldash(a[3])) < 0 ||                                    free_and_strdup(&c->x11_options, strnulldash(a[4])) < 0)                                        return -ENOMEM;                                modified = true;                        }                        break;                }        }        if (modified) {                int r;                r = x11_write_data(c);                if (r < 0)                        return log_error_errno(r, "Failed to set X11 keyboard layout: %m");                log_info("Changed X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'",                         strempty(c->x11_layout),                         strempty(c->x11_model),                         strempty(c->x11_variant),                         strempty(c->x11_options));                sd_bus_emit_properties_changed(bus,                                "/org/freedesktop/locale1",                                "org.freedesktop.locale1",                                "X11Layout", "X11Model", "X11Variant", "X11Options", NULL);        } else                log_debug("X11 keyboard layout was not modified.");        return 0;}
开发者ID:vlajos,项目名称:systemd,代码行数:75,


示例25: _nss_myhostname_gethostbyname3_r

enum nss_status _nss_myhostname_gethostbyname3_r(                const char *name,                int af,                struct hostent *host,                char *buffer, size_t buflen,                int *errnop, int *h_errnop,                int32_t *ttlp,                char **canonp) {        _cleanup_free_ struct local_address *addresses = NULL;        const char *canonical, *additional = NULL;        _cleanup_free_ char *hn = NULL;        uint32_t local_address_ipv4 = 0;        int n_addresses = 0;        assert(name);        assert(host);        assert(buffer);        assert(errnop);        assert(h_errnop);        if (af == AF_UNSPEC)                af = AF_INET;        if (af != AF_INET && af != AF_INET6) {                *errnop = EAFNOSUPPORT;                *h_errnop = NO_DATA;                return NSS_STATUS_UNAVAIL;        }        if (is_localhost(name)) {                canonical = "localhost";                local_address_ipv4 = htonl(INADDR_LOOPBACK);        } else if (is_gateway_hostname(name)) {                n_addresses = local_gateways(NULL, 0, af, &addresses);                if (n_addresses <= 0) {                        *errnop = ENOENT;                        *h_errnop = HOST_NOT_FOUND;                        return NSS_STATUS_NOTFOUND;                }                canonical = "gateway";        } else {                hn = gethostname_malloc();                if (!hn) {                        *errnop = ENOMEM;                        *h_errnop = NO_RECOVERY;                        return NSS_STATUS_TRYAGAIN;                }                if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) {                        *errnop = ENOENT;                        *h_errnop = HOST_NOT_FOUND;                        return NSS_STATUS_NOTFOUND;                }                n_addresses = local_addresses(NULL, 0, af, &addresses);                if (n_addresses < 0)                        n_addresses = 0;                canonical = hn;                additional = n_addresses <= 0 && af == AF_INET6 ? "localhost" : NULL;                local_address_ipv4 = LOCALADDRESS_IPV4;        }        return fill_in_hostent(                        canonical, additional,                        af,                        addresses, n_addresses,                        local_address_ipv4,                        host,                        buffer, buflen,                        errnop, h_errnop,                        ttlp,                        canonp);}
开发者ID:abbradar,项目名称:systemd,代码行数:79,


示例26: test_specifier_escape_one

static void test_specifier_escape_one(const char *a, const char *b) {        _cleanup_free_ char *x = NULL;        x = specifier_escape(a);        assert_se(streq_ptr(x, b));}
开发者ID:dankor,项目名称:systemd,代码行数:6,


示例27: test_parse_env_file

static void test_parse_env_file(void) {        char    t[] = "/tmp/test-fileio-in-XXXXXX",                p[] = "/tmp/test-fileio-out-XXXXXX";        int fd, r;        FILE *f;        _cleanup_free_ char *one = NULL, *two = NULL, *three = NULL, *four = NULL, *five = NULL,                        *six = NULL, *seven = NULL, *eight = NULL, *nine = NULL, *ten = NULL;        _cleanup_strv_free_ char **a = NULL, **b = NULL;        char **i;        unsigned k;        fd = mkostemp_safe(p, O_RDWR|O_CLOEXEC);        assert_se(fd >= 0);        close(fd);        fd = mkostemp_safe(t, O_RDWR|O_CLOEXEC);        assert_se(fd >= 0);        f = fdopen(fd, "w");        assert_se(f);        fputs("one=BAR   /n"              "# comment/n"              " # comment /n"              " ; comment /n"              "  two   =   bar    /n"              "invalid line/n"              "invalid line #comment/n"              "three = /"333/n"              "xxxx/"/n"              "four = /'44///"44/'/n"              "five = /'55///'55/' /"FIVE/" cinco   /n"              "six = seis sechs///n"              " sis/n"              "seven=/"sevenval/" #nocomment/n"              "eight=eightval #nocomment/n"              "export nine=nineval/n"              "ten=", f);        fflush(f);        fclose(f);        r = load_env_file(t, NULL, &a);        assert_se(r >= 0);        STRV_FOREACH(i, a)                log_info("Got: <%s>", *i);        assert_se(streq_ptr(a[0], "one=BAR"));        assert_se(streq_ptr(a[1], "two=bar"));        assert_se(streq_ptr(a[2], "three=333/nxxxx"));        assert_se(streq_ptr(a[3], "four=44/"44"));        assert_se(streq_ptr(a[4], "five=55/'55FIVEcinco"));        assert_se(streq_ptr(a[5], "six=seis sechs sis"));        assert_se(streq_ptr(a[6], "seven=sevenval#nocomment"));        assert_se(streq_ptr(a[7], "eight=eightval #nocomment"));        assert_se(streq_ptr(a[8], "export nine=nineval"));        assert_se(streq_ptr(a[9], "ten="));        assert_se(a[10] == NULL);        strv_env_clean_log(a, "test");        k = 0;        STRV_FOREACH(i, b) {                log_info("Got2: <%s>", *i);                assert_se(streq(*i, a[k++]));        }
开发者ID:MOBO-OSS,项目名称:systemd-relative,代码行数:67,


示例28: check_p_g_u_slice

static void check_p_g_u_slice(const char *path, int code, const char *result) {        _cleanup_free_ char *s = NULL;        assert_se(cg_path_get_user_slice(path, &s) == code);        assert_se(streq_ptr(s, result));}
开发者ID:nazgul77,项目名称:systemd,代码行数:6,


示例29: set_machine_info

static int set_machine_info(Context *c, sd_bus_message *m, int prop, sd_bus_message_handler_t cb, sd_bus_error *error) {    int interactive;    const char *name;    int r;    assert(c);    assert(m);    r = sd_bus_message_read(m, "sb", &name, &interactive);    if (r < 0)        return r;    if (isempty(name))        name = NULL;    if (streq_ptr(name, c->data[prop]))        return sd_bus_reply_method_return(m, NULL);    /* Since the pretty hostname should always be changed at the     * same time as the static one, use the same policy action for     * both... */    r = bus_verify_polkit_async(            m,            CAP_SYS_ADMIN,            prop == PROP_PRETTY_HOSTNAME ? "org.freedesktop.hostname1.set-static-hostname" : "org.freedesktop.hostname1.set-machine-info",            NULL,            interactive,            UID_INVALID,            &c->polkit_registry,            error);    if (r < 0)        return r;    if (r == 0)        return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */    if (isempty(name)) {        c->data[prop] = mfree(c->data[prop]);    } else {        char *h;        /* The icon name might ultimately be used as file         * name, so better be safe than sorry */        if (prop == PROP_ICON_NAME && !filename_is_valid(name))            return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid icon name '%s'", name);        if (prop == PROP_PRETTY_HOSTNAME && string_has_cc(name, NULL))            return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid pretty host name '%s'", name);        if (prop == PROP_CHASSIS && !valid_chassis(name))            return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid chassis '%s'", name);        if (prop == PROP_DEPLOYMENT && !valid_deployment(name))            return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid deployment '%s'", name);        if (prop == PROP_LOCATION && string_has_cc(name, NULL))            return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid location '%s'", name);        h = strdup(name);        if (!h)            return -ENOMEM;        free(c->data[prop]);        c->data[prop] = h;    }    r = context_write_data_machine_info(c);    if (r < 0) {        log_error_errno(r, "Failed to write machine info: %m");        return sd_bus_error_set_errnof(error, r, "Failed to write machine info: %s", strerror(-r));    }    log_info("Changed %s to '%s'",             prop == PROP_PRETTY_HOSTNAME ? "pretty host name" :             prop == PROP_DEPLOYMENT ? "deployment" :             prop == PROP_LOCATION ? "location" :             prop == PROP_CHASSIS ? "chassis" : "icon name", strna(c->data[prop]));    (void) sd_bus_emit_properties_changed(        sd_bus_message_get_bus(m),        "/org/freedesktop/hostname1",        "org.freedesktop.hostname1",        prop == PROP_PRETTY_HOSTNAME ? "PrettyHostname" :        prop == PROP_DEPLOYMENT ? "Deployment" :        prop == PROP_LOCATION ? "Location" :        prop == PROP_CHASSIS ? "Chassis" : "IconName" , NULL);    return sd_bus_reply_method_return(m, NULL);}
开发者ID:NetworkManager,项目名称:systemd,代码行数:86,


示例30: test_slice_to_path_one

static void test_slice_to_path_one(const char *unit, const char *path, int error) {        _cleanup_free_ char *ret = NULL;        assert_se(cg_slice_to_path(unit, &ret) == error);        assert_se(streq_ptr(ret, path));}
开发者ID:nazgul77,项目名称:systemd,代码行数:6,



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


C++ strequal函数代码示例
C++ streq函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。