all: unify and rename strv helper API

Naming is important, because the name of a thing should give you a good
idea what it does. Also, to find a thing, it needs a good name in the
first place. But naming is also hard.

Historically, some strv helper API was named as nm_utils_strv_*(),
and some API had a leading underscore (as it is internal API).

This was all inconsistent. Do some renaming and try to unify things.

We get rid of the leading underscore if this is just a regular
(internal) helper. But not for example from _nm_strv_find_first(),
because that is the implementation of nm_strv_find_first().

  - _nm_utils_strv_cleanup()                 -> nm_strv_cleanup()
  - _nm_utils_strv_cleanup_const()           -> nm_strv_cleanup_const()
  - _nm_utils_strv_cmp_n()                   -> _nm_strv_cmp_n()
  - _nm_utils_strv_dup()                     -> _nm_strv_dup()
  - _nm_utils_strv_dup_packed()              -> _nm_strv_dup_packed()
  - _nm_utils_strv_find_first()              -> _nm_strv_find_first()
  - _nm_utils_strv_sort()                    -> _nm_strv_sort()
  - _nm_utils_strv_to_ptrarray()             -> nm_strv_to_ptrarray()
  - _nm_utils_strv_to_slist()                -> nm_strv_to_gslist()
  - nm_utils_strv_cmp_n()                    -> nm_strv_cmp_n()
  - nm_utils_strv_dup()                      -> nm_strv_dup()
  - nm_utils_strv_dup_packed()               -> nm_strv_dup_packed()
  - nm_utils_strv_dup_shallow_maybe_a()      -> nm_strv_dup_shallow_maybe_a()
  - nm_utils_strv_equal()                    -> nm_strv_equal()
  - nm_utils_strv_find_binary_search()       -> nm_strv_find_binary_search()
  - nm_utils_strv_find_first()               -> nm_strv_find_first()
  - nm_utils_strv_make_deep_copied()         -> nm_strv_make_deep_copied()
  - nm_utils_strv_make_deep_copied_n()       -> nm_strv_make_deep_copied_n()
  - nm_utils_strv_make_deep_copied_nonnull() -> nm_strv_make_deep_copied_nonnull()
  - nm_utils_strv_sort()                     -> nm_strv_sort()

Note that no names are swapped and none of the new names existed
previously. That means, all the new names are really new, which
simplifies to find errors due to this larger refactoring. E.g. if
you backport a patch from after this change to an old branch, you'll
get a compiler error and notice that something is missing.
This commit is contained in:
Thomas Haller 2021-07-29 10:02:11 +02:00
parent 3775f4395a
commit 4c3aac899e
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
47 changed files with 208 additions and 221 deletions

View file

@ -112,7 +112,7 @@ get_new_connection_name(NMConnection *const *existing_connections,
* connection id. */
temp = g_strdup_printf(C_("connection id fallback", "%s %u"), fallback_prefix, i);
if (nm_utils_strv_find_first(existing_names, existing_len, temp) < 0)
if (nm_strv_find_first(existing_names, existing_len, temp) < 0)
return temp;
g_free(temp);

View file

@ -276,7 +276,7 @@ set_arp_targets(NMDevice *device, const char *cur_arp_ip_target, const char *new
}
}
if (nm_utils_strv_find_first(new_strv, i, s) < 0)
if (nm_strv_find_first(new_strv, i, s) < 0)
new_strv[j++] = s;
}
new_strv[j] = NULL;
@ -286,7 +286,7 @@ set_arp_targets(NMDevice *device, const char *cur_arp_ip_target, const char *new
if (cur_len == 0 && new_len == 0)
return;
if (nm_utils_strv_equal(cur_strv, new_strv))
if (nm_strv_equal(cur_strv, new_strv))
return;
for (i = 0; i < cur_len; i++)

View file

@ -12426,7 +12426,7 @@ _nm_device_hash_check_invalid_keys(GHashTable * hash,
g_hash_table_iter_init(&iter, hash);
while (g_hash_table_iter_next(&iter, (gpointer *) &k, NULL)) {
if (nm_utils_strv_find_first(whitelist, -1, k) < 0) {
if (nm_strv_find_first(whitelist, -1, k) < 0) {
first_invalid_key = k;
break;
}

View file

@ -2651,7 +2651,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
break;
case PROP_ACCESS_POINTS:
list = nm_wifi_aps_get_paths(&priv->aps_lst_head, TRUE);
g_value_take_boxed(value, nm_utils_strv_make_deep_copied(list));
g_value_take_boxed(value, nm_strv_make_deep_copied(list));
break;
case PROP_ACTIVE_ACCESS_POINT:
nm_dbus_utils_g_value_set_object_path(value, priv->current_ap);

View file

@ -1193,7 +1193,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
switch (prop_id) {
case PROP_PEERS:
list = nm_wifi_p2p_peers_get_paths(&priv->peers_lst_head);
g_value_take_boxed(value, nm_utils_strv_make_deep_copied(list));
g_value_take_boxed(value, nm_strv_make_deep_copied(list));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);

View file

@ -3641,7 +3641,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
break;
case PROP_ACCESS_POINTS:
list = nm_wifi_aps_get_paths(&priv->aps_lst_head, TRUE);
g_value_take_boxed(value, nm_utils_strv_make_deep_copied(list));
g_value_take_boxed(value, nm_strv_make_deep_copied(list));
break;
case PROP_ACTIVE_ACCESS_POINT:
nm_dbus_utils_g_value_set_object_path(value, priv->current_ap);

View file

@ -408,9 +408,9 @@ nm_wifi_p2p_peer_update_from_properties(NMWifiP2PPeer *peer, const NMSupplicantP
/* We currently only use the groups information internally to check if
* the peer is still joined. */
if (!nm_utils_strv_equal(priv->groups, peer_info->groups)) {
if (!nm_strv_equal(priv->groups, peer_info->groups)) {
g_free(priv->groups);
priv->groups = nm_utils_strv_dup_packed(peer_info->groups, -1);
priv->groups = nm_strv_dup_packed(peer_info->groups, -1);
changed |= TRUE;
}

View file

@ -1124,7 +1124,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
break;
case PROP_REJECT_SERVERS:
/* construct-only */
priv->reject_servers = nm_utils_strv_dup_packed(g_value_get_boxed(value), -1);
priv->reject_servers = nm_strv_dup_packed(g_value_get_boxed(value), -1);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);

View file

@ -1327,7 +1327,7 @@ get_ip_rdns_domains(NMIPConfig *ip_config)
/* Free the array and return NULL if the only element was the ending NULL */
strv = (char **) g_ptr_array_free(domains, (domains->len == 1));
return _nm_utils_strv_cleanup(strv, FALSE, FALSE, TRUE);
return nm_strv_cleanup(strv, FALSE, FALSE, TRUE);
}
static gboolean
@ -1744,8 +1744,8 @@ plugin_skip:;
nameservers = g_new0(char *, 2);
nameservers[0] = g_strdup(lladdr);
need_edns0 = nm_utils_strv_find_first(options, -1, NM_SETTING_DNS_OPTION_EDNS0) < 0;
need_trust = nm_utils_strv_find_first(options, -1, NM_SETTING_DNS_OPTION_TRUST_AD) < 0;
need_edns0 = nm_strv_find_first(options, -1, NM_SETTING_DNS_OPTION_EDNS0) < 0;
need_trust = nm_strv_find_first(options, -1, NM_SETTING_DNS_OPTION_TRUST_AD) < 0;
if (need_edns0 || need_trust) {
gsize len;
@ -2128,7 +2128,7 @@ _resolvconf_resolved_managed(void)
* We want to handle that, because systemd-resolved might not
* have started yet. */
full_path = g_file_read_link(_PATH_RESCONF, NULL);
if (nm_utils_strv_find_first(RESOLVED_PATHS, G_N_ELEMENTS(RESOLVED_PATHS), full_path) >= 0)
if (nm_strv_find_first(RESOLVED_PATHS, G_N_ELEMENTS(RESOLVED_PATHS), full_path) >= 0)
return TRUE;
/* see if resolv.conf is a symlink that resolves exactly one
@ -2140,7 +2140,7 @@ _resolvconf_resolved_managed(void)
* We want to handle that, because systemd-resolved might not
* have started yet. */
real_path = realpath(_PATH_RESCONF, NULL);
if (nm_utils_strv_find_first(RESOLVED_PATHS, G_N_ELEMENTS(RESOLVED_PATHS), real_path) >= 0)
if (nm_strv_find_first(RESOLVED_PATHS, G_N_ELEMENTS(RESOLVED_PATHS), real_path) >= 0)
return TRUE;
/* fall-through and resolve the symlink, to check the file

View file

@ -271,7 +271,7 @@ nm_config_data_get_plugins(const NMConfigData *self, gboolean allow_default)
NM_CONFIG_DEFAULT_MAIN_PLUGINS);
list = g_key_file_get_string_list(kf, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NULL, NULL);
}
return _nm_utils_strv_cleanup(list, TRUE, TRUE, TRUE);
return nm_strv_cleanup(list, TRUE, TRUE, TRUE);
}
gboolean
@ -1060,7 +1060,7 @@ load_global_dns(GKeyFile *keyfile, gboolean internal)
NULL,
NULL);
if (strv) {
_nm_utils_strv_cleanup(strv, TRUE, TRUE, TRUE);
nm_strv_cleanup(strv, TRUE, TRUE, TRUE);
if (!strv[0])
g_free(strv);
else
@ -1073,7 +1073,7 @@ load_global_dns(GKeyFile *keyfile, gboolean internal)
NULL,
NULL);
if (strv) {
_nm_utils_strv_cleanup(strv, TRUE, TRUE, TRUE);
nm_strv_cleanup(strv, TRUE, TRUE, TRUE);
for (i = 0, j = 0; strv[i]; i++) {
if (_nm_utils_dns_option_validate(strv[i], NULL, NULL, TRUE, NULL))
strv[j++] = strv[i];
@ -1103,7 +1103,7 @@ load_global_dns(GKeyFile *keyfile, gboolean internal)
NULL,
NULL);
if (strv) {
_nm_utils_strv_cleanup(strv, TRUE, TRUE, TRUE);
nm_strv_cleanup(strv, TRUE, TRUE, TRUE);
for (i = 0, j = 0; strv[i]; i++) {
if (nm_utils_ipaddr_is_valid(AF_INET, strv[i])
|| nm_utils_ipaddr_is_valid(AF_INET6, strv[i]))
@ -1128,7 +1128,7 @@ load_global_dns(GKeyFile *keyfile, gboolean internal)
NULL,
NULL);
if (strv) {
options = _nm_utils_strv_cleanup(strv, TRUE, TRUE, TRUE);
options = nm_strv_cleanup(strv, TRUE, TRUE, TRUE);
if (!options[0])
nm_clear_g_free(&options);
}
@ -1240,7 +1240,7 @@ global_dns_domain_from_dbus(char *name, GVariant *variant)
while (g_variant_iter_next(&iter, "{&sv}", &key, &val)) {
if (nm_streq0(key, "servers") && g_variant_is_of_type(val, G_VARIANT_TYPE("as"))) {
strv = g_variant_dup_strv(val, NULL);
_nm_utils_strv_cleanup(strv, TRUE, TRUE, TRUE);
nm_strv_cleanup(strv, TRUE, TRUE, TRUE);
for (i = 0, j = 0; strv && strv[i]; i++) {
if (nm_utils_ipaddr_is_valid(AF_INET, strv[i])
|| nm_utils_ipaddr_is_valid(AF_INET6, strv[i]))
@ -1258,7 +1258,7 @@ global_dns_domain_from_dbus(char *name, GVariant *variant)
} else if (nm_streq0(key, "options") && g_variant_is_of_type(val, G_VARIANT_TYPE("as"))) {
strv = g_variant_dup_strv(val, NULL);
g_strfreev(domain->options);
domain->options = _nm_utils_strv_cleanup(strv, TRUE, TRUE, TRUE);
domain->options = nm_strv_cleanup(strv, TRUE, TRUE, TRUE);
if (!domain->options[0])
nm_clear_g_free(&domain->options);
}
@ -1305,10 +1305,10 @@ nm_global_dns_config_from_dbus(const GValue *value, GError **error)
while (g_variant_iter_next(&iter, "{&sv}", &key, &val)) {
if (nm_streq0(key, "searches") && g_variant_is_of_type(val, G_VARIANT_TYPE("as"))) {
strv = g_variant_dup_strv(val, NULL);
dns_config->searches = _nm_utils_strv_cleanup(strv, TRUE, TRUE, TRUE);
dns_config->searches = nm_strv_cleanup(strv, TRUE, TRUE, TRUE);
} else if (nm_streq0(key, "options") && g_variant_is_of_type(val, G_VARIANT_TYPE("as"))) {
strv = g_variant_dup_strv(val, NULL);
_nm_utils_strv_cleanup(strv, TRUE, TRUE, TRUE);
nm_strv_cleanup(strv, TRUE, TRUE, TRUE);
for (i = 0, j = 0; strv && strv[i]; i++) {
if (_nm_utils_dns_option_validate(strv[i], NULL, NULL, TRUE, NULL))
@ -1370,8 +1370,7 @@ global_dns_equal(NMGlobalDnsConfig *old, NMGlobalDnsConfig *new)
if (!old || !new)
return FALSE;
if (!nm_utils_strv_equal(old->options, new->options)
|| !nm_utils_strv_equal(old->searches, new->searches))
if (!nm_strv_equal(old->options, new->options) || !nm_strv_equal(old->searches, new->searches))
return FALSE;
if ((!old->domains || !new->domains) && old->domains != new->domains)
@ -1389,8 +1388,8 @@ global_dns_equal(NMGlobalDnsConfig *old, NMGlobalDnsConfig *new)
domain_old = value_old;
domain_new = value_new;
if (!nm_utils_strv_equal(domain_old->options, domain_new->options)
|| !nm_utils_strv_equal(domain_old->servers, domain_new->servers))
if (!nm_strv_equal(domain_old->options, domain_new->options)
|| !nm_strv_equal(domain_old->servers, domain_new->servers))
return FALSE;
}
@ -1681,7 +1680,7 @@ _match_section_info_init(MatchSectionInfo *connection_info,
}
keys = g_key_file_get_keys(keyfile, group, &n_keys, NULL);
nm_utils_strv_sort(keys, n_keys);
nm_strv_sort(keys, n_keys);
vals = g_new(NMUtilsNamedValue, n_keys);
@ -1963,8 +1962,8 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
/* sort entries, remove duplicates and empty words. */
value_arr =
len == 0 ? NULL : nm_memdup(value_arr_orig, sizeof(const char *) * (len + 1));
nm_utils_strv_sort(value_arr, len);
_nm_utils_strv_cleanup((char **) value_arr, FALSE, TRUE, TRUE);
nm_strv_sort(value_arr, len);
nm_strv_cleanup((char **) value_arr, FALSE, TRUE, TRUE);
len = NM_PTRARRAY_LEN(value_arr);
j = 0;
@ -1988,7 +1987,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
specs = g_slist_prepend(specs, spec);
}
priv->no_auto_default.arr = nm_utils_strv_dup(value_arr, j, TRUE);
priv->no_auto_default.arr = nm_strv_dup(value_arr, j, TRUE);
priv->no_auto_default.specs = g_slist_reverse(specs);
}
break;

View file

@ -433,7 +433,7 @@ nm_config_set_no_auto_default_for_device(NMConfig *self, NMDevice *device)
len = NM_PTRARRAY_LEN(no_auto_default_current);
idx = nm_utils_strv_find_binary_search(no_auto_default_current, len, spec);
idx = nm_strv_find_binary_search(no_auto_default_current, len, spec);
if (idx >= 0) {
/* @spec is already blocked. We don't have to update our in-memory representation.
* Maybe we should write to no_auto_default_file anew, but let's save that too. */
@ -1122,14 +1122,12 @@ read_config(GKeyFile * keyfile,
/* merge the string lists, by omitting duplicates. */
for (iter_val = old_val; iter_val && *iter_val; iter_val++) {
if (last_char != '-'
|| nm_utils_strv_find_first(new_val, -1, *iter_val) < 0)
if (last_char != '-' || nm_strv_find_first(new_val, -1, *iter_val) < 0)
g_ptr_array_add(new, g_strdup(*iter_val));
}
for (iter_val = new_val; iter_val && *iter_val; iter_val++) {
/* don't add duplicates. That means an "option=a,b"; "option+=a,c" results in "option=a,b,c" */
if (last_char == '+'
&& nm_utils_strv_find_first(old_val, -1, *iter_val) < 0)
if (last_char == '+' && nm_strv_find_first(old_val, -1, *iter_val) < 0)
g_ptr_array_add(new, *iter_val);
else
g_free(*iter_val);
@ -1147,7 +1145,7 @@ read_config(GKeyFile * keyfile,
gs_free char * specs_joined = NULL;
g_ptr_array_add(new, NULL);
specs = _nm_utils_strv_to_slist((char **) new->pdata, FALSE);
specs = nm_strv_to_gslist((char **) new->pdata, FALSE);
specs_joined = nm_match_spec_join(specs);

View file

@ -152,7 +152,7 @@ nm_dbus_utils_g_value_set_object_path_from_hash(
strv[i] = NULL;
/* sort the names, to give a well-defined, stable order. */
nm_utils_strv_sort(strv, i);
nm_strv_sort(strv, i);
g_value_take_boxed(value, strv);
}

View file

@ -323,8 +323,7 @@ _strv_ptrarray_merge(GPtrArray **p_dst, const GPtrArray *src)
const char *s = src->pdata[i];
if (dst_initial_len > 0
&& nm_utils_strv_find_first((const char *const *) ((*p_dst)->pdata), dst_initial_len, s)
>= 0)
&& nm_strv_find_first((const char *const *) ((*p_dst)->pdata), dst_initial_len, s) >= 0)
continue;
g_ptr_array_add(*p_dst, g_strdup(s));

View file

@ -8076,7 +8076,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
g_value_set_boolean(value, priv->sleeping);
break;
case PROP_DEVICES:
g_value_take_boxed(value, nm_utils_strv_make_deep_copied(_get_devices_paths(self, FALSE)));
g_value_take_boxed(value, nm_strv_make_deep_copied(_get_devices_paths(self, FALSE)));
break;
case PROP_METERED:
g_value_set_uint(value, priv->metered);
@ -8087,12 +8087,12 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
nm_global_dns_config_to_dbus(dns_config, value);
break;
case PROP_ALL_DEVICES:
g_value_take_boxed(value, nm_utils_strv_make_deep_copied(_get_devices_paths(self, TRUE)));
g_value_take_boxed(value, nm_strv_make_deep_copied(_get_devices_paths(self, TRUE)));
break;
case PROP_CHECKPOINTS:
g_value_take_boxed(
value,
priv->checkpoint_mgr ? nm_utils_strv_make_deep_copied(
priv->checkpoint_mgr ? nm_strv_make_deep_copied(
nm_checkpoint_manager_get_checkpoint_paths(priv->checkpoint_mgr, NULL))
: NULL);
break;

View file

@ -346,7 +346,7 @@ _getsettings_cached_get(NMSettingsConnection *self, const NMConnectionSerializat
priv->getsettings_cached.options = *options;
priv->getsettings_cached.options.seen_bssids =
nm_utils_strv_dup_packed(priv->getsettings_cached.options.seen_bssids, -1);
nm_strv_dup_packed(priv->getsettings_cached.options.seen_bssids, -1);
return priv->getsettings_cached.variant;
}

View file

@ -3372,7 +3372,7 @@ load_plugins(NMSettings *self, const char *const *plugins, GError **error)
continue;
}
if (nm_utils_strv_find_first(plugins, iter - plugins, pname) >= 0) {
if (nm_strv_find_first(plugins, iter - plugins, pname) >= 0) {
/* the plugin is already mentioned in the list previously.
* Don't load a duplicate. */
continue;
@ -3938,7 +3938,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
priv->connections_len,
G_STRUCT_OFFSET(NMSettingsConnection, _connections_lst),
TRUE);
g_value_take_boxed(value, nm_utils_strv_make_deep_copied(strv));
g_value_take_boxed(value, nm_strv_make_deep_copied(strv));
break;
case PROP_STARTUP_COMPLETE:
g_value_set_boolean(value, !nm_settings_get_startup_complete_blocked_reason(self, FALSE));

View file

@ -934,7 +934,7 @@ _peer_info_properties_changed(NMSupplicantInterface *self,
if (nm_g_variant_lookup(properties, "Groups", "^a&o", &v_strv)) {
g_free(peer_info->groups);
peer_info->groups = nm_utils_strv_dup_packed(v_strv, -1);
peer_info->groups = nm_strv_dup_packed(v_strv, -1);
g_free(v_strv);
}

View file

@ -223,7 +223,7 @@ validate_type_keyword(const struct Opt *opt, const char *value, const guint32 le
s++;
}
if (nm_utils_strv_find_first(opt->str_allowed, -1, value) < 0)
if (nm_strv_find_first(opt->str_allowed, -1, value) < 0)
return FALSE;
if (!s)

View file

@ -3001,7 +3001,7 @@ nm_lldp_neighbor_get_attr_names(NMLldpNeighbor *neighbor)
keys = nm_utils_strdict_get_keys(neighbor->attrs, TRUE, NULL);
return nm_utils_strv_make_deep_copied_nonnull(keys);
return nm_strv_make_deep_copied_nonnull(keys);
}
/**

View file

@ -190,7 +190,7 @@ next:
g_variant_iter_free(iter_v);
}
if (arr && arr->len > 0)
nameservers_new = nm_utils_strv_dup((char **) arr->pdata, arr->len, FALSE);
nameservers_new = nm_strv_dup((char **) arr->pdata, arr->len, FALSE);
else
nameservers_new = g_new0(char *, 1);
}

View file

@ -208,7 +208,7 @@ _fixup_string(const char * desc,
if (eow)
*eow = '\0';
if (nm_utils_strv_find_first(ignored_words, -1, p) >= 0)
if (nm_strv_find_first(ignored_words, -1, p) >= 0)
goto next;
l = strlen(p);

View file

@ -944,8 +944,8 @@ _nm_setting_connection_verify_secondaries(GArray *secondaries, GError **error)
gs_free const char **strv_to_free = NULL;
const char ** strv2;
strv2 = nm_utils_strv_dup_shallow_maybe_a(20, strv, len, &strv_to_free);
nm_utils_strv_sort(strv2, len);
strv2 = nm_strv_dup_shallow_maybe_a(20, strv, len, &strv_to_free);
nm_strv_sort(strv2, len);
has_duplicate = nm_strv_has_duplicate(strv2, len, TRUE);
}
@ -1002,7 +1002,7 @@ _normalize_connection_secondaries(NMConnection *self)
if (!nm_uuid_is_valid_nm(s, &uuid_is_normalized, uuid_normalized))
continue;
if (nm_utils_strv_find_first(strv, j, uuid_is_normalized ? uuid_normalized : s) >= 0)
if (nm_strv_find_first(strv, j, uuid_is_normalized ? uuid_normalized : s) >= 0)
continue;
strv[j++] = uuid_is_normalized ? g_strdup(uuid_normalized) : g_steal_pointer(&s);
@ -2570,8 +2570,7 @@ nm_connection_serialization_options_equal(const NMConnectionSerializationOptions
return FALSE;
if (a->timestamp.has && a->timestamp.val != b->timestamp.val)
return FALSE;
if (!nm_utils_strv_equal(a->seen_bssids ?: NM_STRV_EMPTY_CC(),
b->seen_bssids ?: NM_STRV_EMPTY_CC()))
if (!nm_strv_equal(a->seen_bssids ?: NM_STRV_EMPTY_CC(), b->seen_bssids ?: NM_STRV_EMPTY_CC()))
return FALSE;
return TRUE;

View file

@ -3384,7 +3384,7 @@ _read_setting(KeyfileReaderInfo *info)
if (n_keys > 0) {
GHashTable *h = _nm_setting_option_hash(setting, TRUE);
nm_utils_strv_sort(keys, n_keys);
nm_strv_sort(keys, n_keys);
for (k = 0; k < n_keys; k++) {
gs_free char *key = keys[k];
gs_free_error GError *local = NULL;

View file

@ -3269,7 +3269,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
switch (prop_id) {
case PROP_EAP:
g_slist_free_full(priv->eap, g_free);
priv->eap = _nm_utils_strv_to_slist(g_value_get_boxed(value), TRUE);
priv->eap = nm_strv_to_gslist(g_value_get_boxed(value), TRUE);
break;
case PROP_IDENTITY:
g_free(priv->identity);
@ -3304,7 +3304,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
break;
case PROP_ALTSUBJECT_MATCHES:
g_slist_free_full(priv->altsubject_matches, g_free);
priv->altsubject_matches = _nm_utils_strv_to_slist(g_value_get_boxed(value), TRUE);
priv->altsubject_matches = nm_strv_to_gslist(g_value_get_boxed(value), TRUE);
break;
case PROP_DOMAIN_SUFFIX_MATCH:
g_free(priv->domain_suffix_match);
@ -3369,7 +3369,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
break;
case PROP_PHASE2_ALTSUBJECT_MATCHES:
g_slist_free_full(priv->phase2_altsubject_matches, g_free);
priv->phase2_altsubject_matches = _nm_utils_strv_to_slist(g_value_get_boxed(value), TRUE);
priv->phase2_altsubject_matches = nm_strv_to_gslist(g_value_get_boxed(value), TRUE);
break;
case PROP_PHASE2_DOMAIN_SUFFIX_MATCH:
g_free(priv->phase2_domain_suffix_match);

View file

@ -546,7 +546,7 @@ nm_ip_address_get_attribute_names(NMIPAddress *address)
g_return_val_if_fail(address, NULL);
names = _nm_ip_address_get_attribute_names(address, TRUE, NULL);
return nm_utils_strv_make_deep_copied_nonnull(names);
return nm_strv_make_deep_copied_nonnull(names);
}
/**
@ -1153,7 +1153,7 @@ nm_ip_route_get_attribute_names(NMIPRoute *route)
g_return_val_if_fail(route != NULL, NULL);
names = _nm_ip_route_get_attribute_names(route, TRUE, NULL);
return nm_utils_strv_make_deep_copied_nonnull(names);
return nm_strv_make_deep_copied_nonnull(names);
}
/**
@ -5990,11 +5990,11 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
break;
case PROP_DNS:
g_ptr_array_unref(priv->dns);
priv->dns = _nm_utils_strv_to_ptrarray(g_value_get_boxed(value));
priv->dns = nm_strv_to_ptrarray(g_value_get_boxed(value));
break;
case PROP_DNS_SEARCH:
g_ptr_array_unref(priv->dns_search);
priv->dns_search = _nm_utils_strv_to_ptrarray(g_value_get_boxed(value));
priv->dns_search = nm_strv_to_ptrarray(g_value_get_boxed(value));
break;
case PROP_DNS_OPTIONS:
strv = g_value_get_boxed(value);

View file

@ -595,7 +595,7 @@ nm_tc_action_get_attribute_names(NMTCAction *action)
g_return_val_if_fail(action, NULL);
names = nm_utils_strdict_get_keys(action->attributes, TRUE, NULL);
return nm_utils_strv_make_deep_copied_nonnull(names);
return nm_strv_make_deep_copied_nonnull(names);
}
GHashTable *

View file

@ -278,7 +278,7 @@ foreach_item_helper(NMSettingVpn *self, GHashTable **p_hash, NMVpnIterFunc func,
nm_assert(NM_IS_SETTING_VPN(self));
nm_assert(func);
keys = nm_utils_strv_make_deep_copied(nm_utils_strdict_get_keys(*p_hash, TRUE, &len));
keys = nm_strv_make_deep_copied(nm_utils_strdict_get_keys(*p_hash, TRUE, &len));
if (len == 0u) {
nm_assert(!keys);
return;

View file

@ -147,9 +147,9 @@ _nm_setting_wired_is_valid_s390_option(const char *option)
}
return option
&& (nm_utils_strv_find_binary_search(valid_s390_opts,
G_N_ELEMENTS(valid_s390_opts) - 1,
option)
&& (nm_strv_find_binary_search(valid_s390_opts,
G_N_ELEMENTS(valid_s390_opts) - 1,
option)
>= 0);
}

View file

@ -1408,15 +1408,15 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
break;
case PROP_PROTO:
g_slist_free_full(priv->proto, g_free);
priv->proto = _nm_utils_strv_to_slist(g_value_get_boxed(value), TRUE);
priv->proto = nm_strv_to_gslist(g_value_get_boxed(value), TRUE);
break;
case PROP_PAIRWISE:
g_slist_free_full(priv->pairwise, g_free);
priv->pairwise = _nm_utils_strv_to_slist(g_value_get_boxed(value), TRUE);
priv->pairwise = nm_strv_to_gslist(g_value_get_boxed(value), TRUE);
break;
case PROP_GROUP:
g_slist_free_full(priv->group, g_free);
priv->group = _nm_utils_strv_to_slist(g_value_get_boxed(value), TRUE);
priv->group = nm_strv_to_gslist(g_value_get_boxed(value), TRUE);
break;
case PROP_PMF:
priv->pmf = g_value_get_int(value);

View file

@ -1220,11 +1220,11 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
g_value_set_uint(value, nm_setting_wireless_get_mtu(setting));
break;
case PROP_SEEN_BSSIDS:
g_value_take_boxed(value,
priv->seen_bssids ? nm_utils_strv_dup((char **) priv->seen_bssids->pdata,
priv->seen_bssids->len,
TRUE)
: NULL);
g_value_take_boxed(
value,
priv->seen_bssids
? nm_strv_dup((char **) priv->seen_bssids->pdata, priv->seen_bssids->len, TRUE)
: NULL);
break;
case PROP_HIDDEN:
g_value_set_boolean(value, nm_setting_wireless_get_hidden(setting));

View file

@ -523,11 +523,10 @@ _team_attr_data_cmp(const TeamAttrData *attr_data,
} else if (!is_port && attr_data->team_attr == NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_HASH) {
v_ptrarray_a = *((const GPtrArray *const *) val_a);
v_ptrarray_b = *((const GPtrArray *const *) val_b);
NM_CMP_RETURN(
nm_utils_strv_cmp_n(v_ptrarray_a ? (const char *const *) v_ptrarray_a->pdata : NULL,
v_ptrarray_a ? v_ptrarray_a->len : 0u,
v_ptrarray_b ? (const char *const *) v_ptrarray_b->pdata : NULL,
v_ptrarray_b ? v_ptrarray_b->len : 0u));
NM_CMP_RETURN(nm_strv_cmp_n(v_ptrarray_a ? (const char *const *) v_ptrarray_a->pdata : NULL,
v_ptrarray_a ? v_ptrarray_a->len : 0u,
v_ptrarray_b ? (const char *const *) v_ptrarray_b->pdata : NULL,
v_ptrarray_b ? v_ptrarray_b->len : 0u));
} else
nm_assert_not_reached();
return 0;
@ -1136,12 +1135,12 @@ _team_setting_value_master_runner_tx_hash_set_list(NMTeamSetting * self,
gboolean changed;
guint i;
if (nm_utils_strv_cmp_n(self->d.master.runner_tx_hash
? (const char *const *) self->d.master.runner_tx_hash->pdata
: NULL,
self->d.master.runner_tx_hash ? self->d.master.runner_tx_hash->len : 0u,
arr,
len)
if (nm_strv_cmp_n(self->d.master.runner_tx_hash
? (const char *const *) self->d.master.runner_tx_hash->pdata
: NULL,
self->d.master.runner_tx_hash ? self->d.master.runner_tx_hash->len : 0u,
arr,
len)
== 0) {
changed = FALSE;
goto out;
@ -2245,7 +2244,7 @@ _team_setting_verify_properties(const NMTeamSetting *self, GError **error)
} else if (attr_data->value_type == NM_VALUE_TYPE_STRING) {
const char *v = *((const char *const *) p_field);
if (nm_utils_strv_find_first(attr_data->range.r_string.valid_names, -1, v) < 0) {
if (nm_strv_find_first(attr_data->range.r_string.valid_names, -1, v) < 0) {
g_set_error(error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_SETTING,
@ -2264,8 +2263,7 @@ _team_setting_verify_properties(const NMTeamSetting *self, GError **error)
for (i = 0; i < self->d.master.runner_tx_hash->len; i++) {
const char *val = self->d.master.runner_tx_hash->pdata[i];
if (!val
|| (nm_utils_strv_find_first(_valid_names_runner_tx_hash, -1, val) < 0)) {
if (!val || (nm_strv_find_first(_valid_names_runner_tx_hash, -1, val) < 0)) {
g_set_error(error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_SETTING,
@ -2291,7 +2289,7 @@ _team_setting_verify_properties(const NMTeamSetting *self, GError **error)
if (!_team_setting_has_field(self, attr_data))
continue;
if (self->d.master.runner
&& (nm_utils_strv_find_first(e->valid_runners, -1, self->d.master.runner) >= 0))
&& (nm_strv_find_first(e->valid_runners, -1, self->d.master.runner) >= 0))
continue;
if (e->valid_runners[1] == NULL) {
g_set_error(error,

View file

@ -838,7 +838,7 @@ _nm_utils_bytes_from_dbus(GVariant *dbus_value, GValue *prop_value)
/*****************************************************************************/
GSList *
_nm_utils_strv_to_slist(char **strv, gboolean deep_copy)
nm_strv_to_gslist(char **strv, gboolean deep_copy)
{
GSList *list = NULL;
gsize i;
@ -887,7 +887,7 @@ _nm_utils_slist_to_strv(const GSList *slist, gboolean deep_copy)
}
GPtrArray *
_nm_utils_strv_to_ptrarray(char **strv)
nm_strv_to_ptrarray(char **strv)
{
GPtrArray *ptrarray;
gsize i, l;

View file

@ -337,7 +337,7 @@ nm_vpn_plugin_info_list_load()
uid = getuid();
for (i = 0; i < G_N_ELEMENTS(dir); i++) {
if (!dir[i] || nm_utils_strv_find_first(dir, i, dir[i]) >= 0)
if (!dir[i] || nm_strv_find_first(dir, i, dir[i]) >= 0)
continue;
infos = _nm_vpn_plugin_info_list_load_dir(dir[i], TRUE, uid, NULL, NULL);
@ -552,7 +552,7 @@ _list_find_by_service(GSList *list, const char *name, const char *service)
if (name && !nm_streq(name, priv->name))
continue;
if (service && !nm_streq(priv->service, service)
&& (nm_utils_strv_find_first(priv->aliases, -1, service) < 0))
&& (nm_strv_find_first(priv->aliases, -1, service) < 0))
continue;
return list->data;
@ -639,7 +639,7 @@ nm_vpn_plugin_info_list_find_service_type(GSList *list, const char *name)
/* check the hard-coded list of short-names. They all have the same
* well-known prefix org.freedesktop.NetworkManager and the name. */
if (nm_utils_strv_find_first(known_names, G_N_ELEMENTS(known_names), name) >= 0)
if (nm_strv_find_first(known_names, G_N_ELEMENTS(known_names), name) >= 0)
return g_strdup_printf("%s.%s", NM_DBUS_INTERFACE, name);
/* try, if there exists a plugin with @name under org.freedesktop.NetworkManager.

View file

@ -619,7 +619,7 @@ _do_test_nm_utils_strsplit_set_f_one(NMUtilsStrsplitSetFlags flags,
}
g_assert(words_g[words_len] == NULL);
g_assert_cmpint(NM_PTRARRAY_LEN(words_g), ==, words_len);
g_assert(nm_utils_strv_cmp_n(exp_words, words_len, words_g, -1) == 0);
g_assert(nm_strv_cmp_n(exp_words, words_len, words_g, -1) == 0);
}
}
@ -643,7 +643,7 @@ _do_test_nm_utils_strsplit_set_f_one(NMUtilsStrsplitSetFlags flags,
g_assert_cmpstr(exp_words[i], ==, words[i]);
g_assert(words[words_len] == NULL);
g_assert(nm_utils_strv_cmp_n(exp_words, words_len, words, -1) == 0);
g_assert(nm_strv_cmp_n(exp_words, words_len, words, -1) == 0);
s1 = words[0];
g_assert(s1 >= (char *) &words[words_len + 1]);
@ -804,7 +804,7 @@ _do_test_nm_utils_strsplit_set_simple(NMUtilsStrsplitSetFlags flags,
g_assert_cmpint(words_len, >, 0);
n_tokens = NM_PTRARRAY_LEN(tokens);
if (nm_utils_strv_cmp_n(exp_words, words_len, tokens, -1) != 0) {
if (nm_strv_cmp_n(exp_words, words_len, tokens, -1) != 0) {
gsize i;
g_print(">>> split \"%s\" (flags %x) got %zu tokens (%zu expected)\n",
@ -10466,7 +10466,7 @@ _strsplit_quoted_assert_strv(const char * topic,
g_assert(strv1);
g_assert(strv2);
if (nm_utils_strv_equal(strv1, strv2))
if (nm_strv_equal(strv1, strv2))
return;
for (i = 0; strv1[i]; i++) {

View file

@ -3249,7 +3249,7 @@ _rndt_wired_add_s390_options(NMSettingWired *s_wired, char **out_keyfile_entries
g_assert(k);
g_assert(v);
idx = nm_utils_strv_find_first(opt_keys, n_opts, k);
idx = nm_strv_find_first(opt_keys, n_opts, k);
g_assert(idx >= 0);
g_assert(!opt_found[idx]);
opt_found[idx] = TRUE;
@ -4860,44 +4860,44 @@ test_setting_connection_secondaries_verify(void)
g_object_set(s_con, NM_SETTING_CONNECTION_SECONDARIES, arr->pdata, NULL);
#define _assert_secondaries(s_con, expected) \
G_STMT_START \
{ \
NMSettingConnection *const _s_con = (s_con); \
const char *const * _expected = (expected); \
GArray * _secondaries; \
const guint _expected_len = NM_PTRARRAY_LEN(_expected); \
gs_strfreev char ** _sec_strv = NULL; \
guint _i; \
\
g_assert(_expected); \
\
if (nmtst_get_rand_bool()) { \
_secondaries = _nm_setting_connection_get_secondaries(_s_con); \
g_assert_cmpint(_expected_len, ==, nm_g_array_len(_secondaries)); \
g_assert((_expected_len == 0) == (!_secondaries)); \
g_assert(nm_utils_strv_equal(_expected, \
_secondaries ? nm_strvarray_get_strv(&_secondaries, NULL) \
: NM_PTRARRAY_EMPTY(const char *))); \
} \
\
if (nmtst_get_rand_bool()) { \
g_object_get(_s_con, NM_SETTING_CONNECTION_SECONDARIES, &_sec_strv, NULL); \
g_assert_cmpint(_expected_len, ==, NM_PTRARRAY_LEN(_sec_strv)); \
g_assert((_expected_len == 0) == (!_sec_strv)); \
g_assert(nm_utils_strv_equal(_expected, _sec_strv ?: NM_STRV_EMPTY())); \
} \
\
g_assert_cmpint(nm_setting_connection_get_num_secondaries(_s_con), ==, _expected_len); \
if (nmtst_get_rand_bool()) { \
for (_i = 0; _i < _expected_len; _i++) { \
g_assert_cmpstr(nm_setting_connection_get_secondary(_s_con, _i), \
==, \
_expected[_i]); \
} \
g_assert_null(nm_setting_connection_get_secondary(_s_con, _expected_len)); \
} \
} \
#define _assert_secondaries(s_con, expected) \
G_STMT_START \
{ \
NMSettingConnection *const _s_con = (s_con); \
const char *const * _expected = (expected); \
GArray * _secondaries; \
const guint _expected_len = NM_PTRARRAY_LEN(_expected); \
gs_strfreev char ** _sec_strv = NULL; \
guint _i; \
\
g_assert(_expected); \
\
if (nmtst_get_rand_bool()) { \
_secondaries = _nm_setting_connection_get_secondaries(_s_con); \
g_assert_cmpint(_expected_len, ==, nm_g_array_len(_secondaries)); \
g_assert((_expected_len == 0) == (!_secondaries)); \
g_assert(nm_strv_equal(_expected, \
_secondaries ? nm_strvarray_get_strv(&_secondaries, NULL) \
: NM_PTRARRAY_EMPTY(const char *))); \
} \
\
if (nmtst_get_rand_bool()) { \
g_object_get(_s_con, NM_SETTING_CONNECTION_SECONDARIES, &_sec_strv, NULL); \
g_assert_cmpint(_expected_len, ==, NM_PTRARRAY_LEN(_sec_strv)); \
g_assert((_expected_len == 0) == (!_sec_strv)); \
g_assert(nm_strv_equal(_expected, _sec_strv ?: NM_STRV_EMPTY())); \
} \
\
g_assert_cmpint(nm_setting_connection_get_num_secondaries(_s_con), ==, _expected_len); \
if (nmtst_get_rand_bool()) { \
for (_i = 0; _i < _expected_len; _i++) { \
g_assert_cmpstr(nm_setting_connection_get_secondary(_s_con, _i), \
==, \
_expected[_i]); \
} \
g_assert_null(nm_setting_connection_get_secondary(_s_con, _expected_len)); \
} \
} \
G_STMT_END
_assert_secondaries(s_con, (const char *const *) arr->pdata);
@ -4923,7 +4923,7 @@ test_setting_connection_secondaries_verify(void)
}
g_ptr_array_add(arr_norm, NULL);
was_normalized = !nm_utils_strv_equal((char **) arr->pdata, (char **) arr_norm->pdata);
was_normalized = !nm_strv_equal((char **) arr->pdata, (char **) arr_norm->pdata);
if (was_normalized)
nmtst_assert_connection_verifies_and_normalizable(con);

View file

@ -341,10 +341,10 @@ GPtrArray *
_nm_utils_copy_array(const GPtrArray *array, NMUtilsCopyFunc copy_func, GDestroyNotify free_func);
GPtrArray *_nm_utils_copy_object_array(const GPtrArray *array);
GSList *_nm_utils_strv_to_slist(char **strv, gboolean deep_copy);
GSList *nm_strv_to_gslist(char **strv, gboolean deep_copy);
char ** _nm_utils_slist_to_strv(const GSList *slist, gboolean deep_copy);
GPtrArray *_nm_utils_strv_to_ptrarray(char **strv);
GPtrArray *nm_strv_to_ptrarray(char **strv);
char ** _nm_utils_ptrarray_to_strv(const GPtrArray *ptrarray);
gboolean _nm_utils_check_file(const char * filename,

View file

@ -2261,7 +2261,7 @@ nm_utils_strsplit_quoted(const char *str)
/*****************************************************************************/
/**
* _nm_utils_strv_find_first:
* _nm_strv_find_first:
* @list: the strv list to search
* @len: the length of the list, or a negative value if @list is %NULL terminated.
* @needle: the value to search for. The search is done using strcmp().
@ -2274,7 +2274,7 @@ nm_utils_strsplit_quoted(const char *str)
* Returns: index of first occurrence or -1 if @needle is not found in @list.
*/
gssize
_nm_utils_strv_find_first(const char *const *list, gssize len, const char *needle)
_nm_strv_find_first(const char *const *list, gssize len, const char *needle)
{
gssize i;
@ -2370,8 +2370,8 @@ nm_strv_is_same_unordered(const char *const *strv1,
if (l > 1) {
strv1 = nm_memdup_maybe_a(300, strv1, sizeof(char *) * l, &ss1_free);
strv2 = nm_memdup_maybe_a(300, strv2, sizeof(char *) * l2, &ss2_free);
_nm_utils_strv_sort((const char **) strv1, l);
_nm_utils_strv_sort((const char **) strv2, l);
_nm_strv_sort((const char **) strv1, l);
_nm_strv_sort((const char **) strv2, l);
}
for (i = 0; i < l; i++) {
@ -2383,7 +2383,7 @@ nm_strv_is_same_unordered(const char *const *strv1,
}
const char **
_nm_utils_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean skip_repeated)
nm_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean skip_repeated)
{
gsize i;
gsize j;
@ -2397,7 +2397,7 @@ _nm_utils_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean sk
j = 0;
for (i = 0; strv[i]; i++) {
if ((skip_empty && !*strv[i])
|| (skip_repeated && nm_utils_strv_find_first(strv, j, strv[i]) >= 0))
|| (skip_repeated && nm_strv_find_first(strv, j, strv[i]) >= 0))
continue;
strv[j++] = strv[i];
}
@ -2406,10 +2406,7 @@ _nm_utils_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean sk
}
char **
_nm_utils_strv_cleanup(char ** strv,
gboolean strip_whitespace,
gboolean skip_empty,
gboolean skip_repeated)
nm_strv_cleanup(char **strv, gboolean strip_whitespace, gboolean skip_empty, gboolean skip_repeated)
{
gsize i;
gsize j;
@ -2428,7 +2425,7 @@ _nm_utils_strv_cleanup(char ** strv,
j = 0;
for (i = 0; strv[i]; i++) {
if ((skip_empty && !*strv[i])
|| (skip_repeated && nm_utils_strv_find_first(strv, j, strv[i]) >= 0))
|| (skip_repeated && nm_strv_find_first(strv, j, strv[i]) >= 0))
g_free(strv[i]);
else
strv[j++] = strv[i];
@ -3831,7 +3828,7 @@ nm_utils_hashtable_cmp(const GHashTable *a,
}
char **
nm_utils_strv_make_deep_copied(const char **strv)
nm_strv_make_deep_copied(const char **strv)
{
gsize i;
@ -3848,7 +3845,7 @@ nm_utils_strv_make_deep_copied(const char **strv)
}
char **
nm_utils_strv_make_deep_copied_n(const char **strv, gsize len)
nm_strv_make_deep_copied_n(const char **strv, gsize len)
{
gsize i;
@ -3891,7 +3888,7 @@ nm_utils_strv_make_deep_copied_n(const char **strv, gsize len)
* cloned or not.
*/
char **
_nm_utils_strv_dup(const char *const *strv, gssize len, gboolean deep_copied)
_nm_strv_dup(const char *const *strv, gssize len, gboolean deep_copied)
{
gsize i, l;
char **v;
@ -3927,7 +3924,7 @@ _nm_utils_strv_dup(const char *const *strv, gssize len, gboolean deep_copied)
}
const char **
_nm_utils_strv_dup_packed(const char *const *strv, gssize len)
_nm_strv_dup_packed(const char *const *strv, gssize len)
{
gs_free gsize *str_len_free = NULL;
@ -4316,7 +4313,7 @@ fail:
/*****************************************************************************/
/**
* _nm_utils_strv_sort:
* _nm_strv_sort:
* @strv: pointer containing strings that will be sorted
* in-place, %NULL is allowed, unless @len indicates
* that there are more elements.
@ -4330,7 +4327,7 @@ fail:
* comparison.
*/
void
_nm_utils_strv_sort(const char **strv, gssize len)
_nm_strv_sort(const char **strv, gssize len)
{
GCompareDataFunc cmp;
gsize l;
@ -4352,7 +4349,7 @@ _nm_utils_strv_sort(const char **strv, gssize len)
}
/**
* _nm_utils_strv_cmp_n:
* _nm_strv_cmp_n:
* @strv1: a string array
* @len1: the length of @strv1, or -1 for NULL terminated array.
* @strv2: a string array
@ -4375,7 +4372,7 @@ _nm_utils_strv_sort(const char **strv, gssize len)
* Returns: 0 if the arrays are equal (using strcmp).
**/
int
_nm_utils_strv_cmp_n(const char *const *strv1, gssize len1, const char *const *strv2, gssize len2)
_nm_strv_cmp_n(const char *const *strv1, gssize len1, const char *const *strv2, gssize len2)
{
gsize n, n2;

View file

@ -737,20 +737,19 @@ nm_utils_strsplit_set(const char *str, const char *delimiters)
return nm_utils_strsplit_set_full(str, delimiters, NM_UTILS_STRSPLIT_SET_FLAGS_NONE);
}
gssize _nm_utils_strv_find_first(const char *const *list, gssize len, const char *needle);
gssize _nm_strv_find_first(const char *const *list, gssize len, const char *needle);
#define nm_utils_strv_find_first(list, len, needle) \
_nm_utils_strv_find_first(NM_CAST_STRV_CC(list), (len), (needle))
#define nm_strv_find_first(list, len, needle) \
_nm_strv_find_first(NM_CAST_STRV_CC(list), (len), (needle))
gboolean nm_strv_has_duplicate(const char *const *list, gssize len, gboolean is_sorted);
const char **
_nm_utils_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean skip_repeated);
const char **nm_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean skip_repeated);
char **_nm_utils_strv_cleanup(char ** strv,
gboolean strip_whitespace,
gboolean skip_empty,
gboolean skip_repeated);
char **nm_strv_cleanup(char ** strv,
gboolean strip_whitespace,
gboolean skip_empty,
gboolean skip_repeated);
gboolean nm_strv_is_same_unordered(const char *const *strv1,
gssize len1,
@ -2004,26 +2003,26 @@ int nm_utils_hashtable_cmp(const GHashTable *a,
GCompareDataFunc cmp_values,
gpointer user_data);
char **nm_utils_strv_make_deep_copied(const char **strv);
char **nm_strv_make_deep_copied(const char **strv);
char **nm_utils_strv_make_deep_copied_n(const char **strv, gsize len);
char **nm_strv_make_deep_copied_n(const char **strv, gsize len);
static inline char **
nm_utils_strv_make_deep_copied_nonnull(const char **strv)
nm_strv_make_deep_copied_nonnull(const char **strv)
{
return nm_utils_strv_make_deep_copied(strv) ?: g_new0(char *, 1);
return nm_strv_make_deep_copied(strv) ?: g_new0(char *, 1);
}
char **_nm_utils_strv_dup(const char *const *strv, gssize len, gboolean deep_copied);
char **_nm_strv_dup(const char *const *strv, gssize len, gboolean deep_copied);
#define nm_utils_strv_dup(strv, len, deep_copied) \
_nm_utils_strv_dup(NM_CAST_STRV_CC(strv), (len), (deep_copied))
#define nm_strv_dup(strv, len, deep_copied) \
_nm_strv_dup(NM_CAST_STRV_CC(strv), (len), (deep_copied))
const char **_nm_utils_strv_dup_packed(const char *const *strv, gssize len);
const char **_nm_strv_dup_packed(const char *const *strv, gssize len);
#define nm_utils_strv_dup_packed(strv, len) _nm_utils_strv_dup_packed(NM_CAST_STRV_CC(strv), (len))
#define nm_strv_dup_packed(strv, len) _nm_strv_dup_packed(NM_CAST_STRV_CC(strv), (len))
#define nm_utils_strv_dup_shallow_maybe_a(alloca_maxlen, strv, len, to_free) \
#define nm_strv_dup_shallow_maybe_a(alloca_maxlen, strv, len, to_free) \
({ \
const char *const *const _strv = NM_CAST_STRV_CC(strv); \
const gssize _len = (len); \
@ -2245,7 +2244,7 @@ gssize nm_utils_ptrarray_find_binary_search_range(gconstpointer * list,
gssize * out_idx_first,
gssize * out_idx_last);
#define nm_utils_strv_find_binary_search(strv, len, needle) \
#define nm_strv_find_binary_search(strv, len, needle) \
({ \
const char *const *const _strv = NM_CAST_STRV_CC(strv); \
const gsize _len = (len); \
@ -2272,16 +2271,15 @@ gssize nm_utils_ptrarray_find_first(gconstpointer *list, gssize len, gconstpoint
/*****************************************************************************/
void _nm_utils_strv_sort(const char **strv, gssize len);
#define nm_utils_strv_sort(strv, len) _nm_utils_strv_sort(NM_CAST_STRV_MC(strv), len)
void _nm_strv_sort(const char **strv, gssize len);
#define nm_strv_sort(strv, len) _nm_strv_sort(NM_CAST_STRV_MC(strv), len)
int
_nm_utils_strv_cmp_n(const char *const *strv1, gssize len1, const char *const *strv2, gssize len2);
int _nm_strv_cmp_n(const char *const *strv1, gssize len1, const char *const *strv2, gssize len2);
#define nm_utils_strv_cmp_n(strv1, len1, strv2, len2) \
_nm_utils_strv_cmp_n(NM_CAST_STRV_CC(strv1), (len1), NM_CAST_STRV_CC(strv2), (len2))
#define nm_strv_cmp_n(strv1, len1, strv2, len2) \
_nm_strv_cmp_n(NM_CAST_STRV_CC(strv1), (len1), NM_CAST_STRV_CC(strv2), (len2))
#define nm_utils_strv_equal(strv1, strv2) (nm_utils_strv_cmp_n((strv1), -1, (strv2), -1) == 0)
#define nm_strv_equal(strv1, strv2) (nm_strv_cmp_n((strv1), -1, (strv2), -1) == 0)
/*****************************************************************************/
@ -2486,7 +2484,7 @@ nm_strv_ptrarray_find_first(const GPtrArray *strv, const char *str)
{
if (!strv)
return -1;
return nm_utils_strv_find_first((const char *const *) strv->pdata, strv->len, str);
return nm_strv_find_first((const char *const *) strv->pdata, strv->len, str);
}
static inline gboolean
@ -2498,14 +2496,14 @@ nm_strv_ptrarray_contains(const GPtrArray *strv, const char *str)
static inline int
nm_strv_ptrarray_cmp(const GPtrArray *a, const GPtrArray *b)
{
/* nm_utils_strv_cmp_n() will treat NULL and empty arrays the same.
/* nm_strv_cmp_n() will treat NULL and empty arrays the same.
* That means, an empty strv array can both be represented by NULL
* and an array of length zero.
* If you need to distinguish between these case, do that yourself. */
return nm_utils_strv_cmp_n((const char *const *) nm_g_ptr_array_pdata(a),
nm_g_ptr_array_len(a),
(const char *const *) nm_g_ptr_array_pdata(b),
nm_g_ptr_array_len(b));
return nm_strv_cmp_n((const char *const *) nm_g_ptr_array_pdata(a),
nm_g_ptr_array_len(a),
(const char *const *) nm_g_ptr_array_pdata(b),
nm_g_ptr_array_len(b));
}
/*****************************************************************************/
@ -2934,7 +2932,7 @@ nm_strvarray_get_strv_non_empty_dup(GArray *arr, guint *length)
NM_SET_OUT(length, arr->len);
strv = &g_array_index(arr, const char *, 0);
return nm_utils_strv_dup(strv, arr->len, TRUE);
return nm_strv_dup(strv, arr->len, TRUE);
}
static inline const char *const *

View file

@ -1032,7 +1032,7 @@ nmtst_rand_perm_strv(const char *const *strv)
/* this returns a (scrambled) SHALLOW copy of the strv array! */
n = NM_PTRARRAY_LEN(strv);
res = (const char **) (nm_utils_strv_dup(strv, n, FALSE) ?: g_new0(char *, 1));
res = (const char **) (nm_strv_dup(strv, n, FALSE) ?: g_new0(char *, 1));
nmtst_rand_perm(NULL, res, res, sizeof(char *), n);
return res;
}

View file

@ -415,8 +415,8 @@ test_strv_cmp(void)
_strv_cmp_fuzz_input((a1), _l1, &_a1_free_shallow, &_a1_free_deep, &_a1, &_a1x); \
_strv_cmp_fuzz_input((a2), _l2, &_a2_free_shallow, &_a2_free_deep, &_a2, &_a2x); \
\
_c1 = nm_utils_strv_cmp_n(_a1, _l1, _a2, _l2); \
_c2 = nm_utils_strv_cmp_n(_a2, _l2, _a1, _l1); \
_c1 = nm_strv_cmp_n(_a1, _l1, _a2, _l2); \
_c2 = nm_strv_cmp_n(_a2, _l2, _a1, _l1); \
if (equal) { \
g_assert_cmpint(_c1, ==, 0); \
g_assert_cmpint(_c2, ==, 0); \
@ -427,8 +427,8 @@ test_strv_cmp(void)
\
/* Compare with self. _strv_cmp_fuzz_input() randomly swapped the arguments (_a1 and _a1x).
* Either way, the arrays must compare equal to their semantically equal alternative. */ \
g_assert_cmpint(nm_utils_strv_cmp_n(_a1, _l1, _a1x, _l1), ==, 0); \
g_assert_cmpint(nm_utils_strv_cmp_n(_a2, _l2, _a2x, _l2), ==, 0); \
g_assert_cmpint(nm_strv_cmp_n(_a1, _l1, _a1x, _l1), ==, 0); \
g_assert_cmpint(nm_strv_cmp_n(_a2, _l2, _a2x, _l2), ==, 0); \
\
_strv_cmp_free_deep(_a1_free_deep, _l1); \
_strv_cmp_free_deep(_a2_free_deep, _l2); \
@ -1031,10 +1031,10 @@ again:
else
g_assert(!data);
g_assert(nm_utils_strv_cmp_n((const char *const *) strv->pdata,
strv->len,
(const char *const *) strv2->pdata,
strv2->len)
g_assert(nm_strv_cmp_n((const char *const *) strv->pdata,
strv->len,
(const char *const *) strv2->pdata,
strv2->len)
== 0);
}
}
@ -1122,15 +1122,14 @@ test_strv_dup_packed(void)
g_assert(NM_PTRARRAY_LEN(strv_src) == strv_len);
strv_cpy =
nm_utils_strv_dup_packed(strv_src,
nmtst_get_rand_bool() ? (gssize) strv_len : (gssize) -1);
nm_strv_dup_packed(strv_src, nmtst_get_rand_bool() ? (gssize) strv_len : (gssize) -1);
if (strv_len == 0)
g_assert(!strv_cpy);
else
g_assert(strv_cpy);
g_assert(NM_PTRARRAY_LEN(strv_cpy) == strv_len);
if (strv_cpy)
g_assert(nm_utils_strv_equal(strv_cpy, strv_src));
g_assert(nm_strv_equal(strv_cpy, strv_src));
}
}

View file

@ -553,7 +553,7 @@ _ASSERT_ethtool_feature_infos(void)
for (k = 0; k < inf->n_kernel_names; k++) {
const char *name = inf->kernel_names[k];
g_assert(nm_utils_strv_find_first(inf->kernel_names, k, name) < 0);
g_assert(nm_strv_find_first(inf->kernel_names, k, name) < 0);
/* these offload features are only informational and cannot be set from user-space
* (NETIF_F_NEVER_CHANGE). We should not track them in _ethtool_feature_infos. */

View file

@ -1702,7 +1702,7 @@ static const char *const *_values_fcn_gobject_enum(ARGS_VALUES_FCN)
/* the gobject_enum.value_infos are currently ignored for the list of
* values. They only declare additional (hidden) aliases for the setter. */
v = nm_utils_strv_make_deep_copied(nm_utils_enum_get_values(gtype, min, max));
v = nm_strv_make_deep_copied(nm_utils_enum_get_values(gtype, min, max));
return (const char *const *) (*out_to_free = v);
}
@ -3589,7 +3589,7 @@ _multilist_remove_by_value_fcn_ip_config_dhcp_reject_servers(NMSettingIPConfig *
gssize idx;
strv = nm_setting_ip_config_get_dhcp_reject_servers(setting, &num);
idx = nm_utils_strv_find_first(strv, num, item);
idx = nm_strv_find_first(strv, num, item);
if (idx >= 0)
nm_setting_ip_config_remove_dhcp_reject_server(setting, idx);
return TRUE;

View file

@ -56,7 +56,7 @@ _test_ri4a(const char *const *addrs_before, const char *const *addrs_new)
changed = nmcs_setting_ip_replace_ipv4_addresses(s_ip, (NMIPAddress **) arr->pdata, arr->len);
g_assert_cmpint(changed, !=, nm_utils_strv_equal(addrs_before, addrs_new));
g_assert_cmpint(changed, !=, nm_strv_equal(addrs_before, addrs_new));
g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip), ==, n);
for (i = 0; i < n; i++) {

View file

@ -404,7 +404,7 @@ _strv_remove(const char **strv, const char *needle)
gsize len;
gsize i;
idx = nm_utils_strv_find_first(strv, -1, needle);
idx = nm_strv_find_first(strv, -1, needle);
if (idx < 0)
return;
@ -476,15 +476,15 @@ _parse_ip_method(const char *kind)
}
/* sort list and remove duplicates. */
nm_utils_strv_sort(strv, -1);
_nm_utils_strv_cleanup_const(strv, TRUE, TRUE);
nm_strv_sort(strv, -1);
nm_strv_cleanup_const(strv, TRUE, TRUE);
if (nm_utils_strv_find_first(strv, -1, "auto") >= 0) {
if (nm_strv_find_first(strv, -1, "auto") >= 0) {
/* if "auto" is present, then "dhcp4", "dhcp6", and "local6" is implied. */
_strv_remove(strv, "dhcp4");
_strv_remove(strv, "dhcp6");
_strv_remove(strv, "local6");
} else if (nm_utils_strv_find_first(strv, -1, "dhcp6") >= 0) {
} else if (nm_strv_find_first(strv, -1, "dhcp6") >= 0) {
/* if "dhcp6" is present, then "local6" is implied. */
_strv_remove(strv, "local6");
}

View file

@ -1303,7 +1303,7 @@ call_cmd(NmCli *nmc, GTask *task, const NMCCommand *cmd, int argc, const char *c
*call = (CmdCall){
.cmd = cmd,
.argc = argc,
.argv = nm_utils_strv_dup(argv, argc, TRUE),
.argv = nm_strv_dup(argv, argc, TRUE),
.task = task,
};
nmc_client_new_async(NULL,

View file

@ -9273,7 +9273,7 @@ do_connection_load(const NMCCommand *cmd, NmCli *nmc, int argc, const char *cons
return;
}
filenames = (const char **) nm_utils_strv_dup(argv, argc, FALSE);
filenames = (const char **) nm_strv_dup(argv, argc, FALSE);
nm_client_load_connections(nmc->client, (char **) filenames, &failures, NULL, &error);
if (error) {

View file

@ -2543,7 +2543,7 @@ do_device_modify(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const
*info = (ModifyInfo){
.nmc = nmc,
.argc = argc,
.argv = nm_utils_strv_dup(argv, argc, TRUE),
.argv = nm_strv_dup(argv, argc, TRUE),
};
nm_device_get_applied_connection_async(device, 0, NULL, modify_get_applied_cb, info);