ssize_t strlevenshtein(const char *x, const char *y);
-static inline int strdup_or_null(const char *s, char **ret) {
- char *c;
-
- assert(ret);
-
- /* This is a lot like strdup(), but is happy with NULL strings, and does not treat that as error, but
- * copies the NULL value. */
-
- if (!s) {
- *ret = NULL;
- return 0;
- }
-
- c = strdup(s);
- if (!c)
- return -ENOMEM;
-
- *ret = c;
- return 1;
-}
-
char *strrstr(const char *haystack, const char *needle);
p->runtime_scope = u->manager->runtime_scope;
- r = strdup_or_null(manager_get_confirm_spawn(u->manager), &p->confirm_spawn);
+ r = strdup_to(&p->confirm_spawn, manager_get_confirm_spawn(u->manager));
if (r < 0)
return r;
assert(where);
assert(ret_options);
- if (!(*flags & (MOUNT_NOAUTO|MOUNT_NOFAIL|MOUNT_AUTOMOUNT))) {
- r = strdup_or_null(options, ret_options);
- if (r < 0)
- return r;
-
- return 0;
- }
+ if (!(*flags & (MOUNT_NOAUTO|MOUNT_NOFAIL|MOUNT_AUTOMOUNT)))
+ return strdup_to(ret_options, options);
log_debug("Mount '%s' is mandatory, ignoring 'noauto', 'nofail', and 'x-systemd.automount' options.",
where);
return copy.rfd;
}
- r = strdup_or_null(source->layout_other, ©.layout_other);
+ r = strdup_to(©.layout_other, source->layout_other);
if (r < 0)
return r;
- r = strdup_or_null(source->conf_root, ©.conf_root);
+ r = strdup_to(©.conf_root, source->conf_root);
if (r < 0)
return r;
- r = strdup_or_null(source->boot_root, ©.boot_root);
+ r = strdup_to(©.boot_root, source->boot_root);
if (r < 0)
return r;
- r = strdup_or_null(source->entry_token, ©.entry_token);
+ r = strdup_to(©.entry_token, source->entry_token);
if (r < 0)
return r;
- r = strdup_or_null(source->entry_dir, ©.entry_dir);
+ r = strdup_to(©.entry_dir, source->entry_dir);
if (r < 0)
return r;
- r = strdup_or_null(source->version, ©.version);
+ r = strdup_to(©.version, source->version);
if (r < 0)
return r;
- r = strdup_or_null(source->kernel, ©.kernel);
+ r = strdup_to(©.kernel, source->kernel);
if (r < 0)
return r;
r = strv_copy_unless_empty(source->initrds, ©.initrds);
if (r < 0)
return r;
- r = strdup_or_null(source->initrd_generator, ©.initrd_generator);
+ r = strdup_to(©.initrd_generator, source->initrd_generator);
if (r < 0)
return r;
- r = strdup_or_null(source->uki_generator, ©.uki_generator);
+ r = strdup_to(©.uki_generator, source->uki_generator);
if (r < 0)
return r;
- r = strdup_or_null(source->staging_area, ©.staging_area);
+ r = strdup_to(©.staging_area, source->staging_area);
if (r < 0)
return r;
r = strv_copy_unless_empty(source->plugins, ©.plugins);
dest->nft_set_context.n_sets = 0;
if (src->family == AF_INET) {
- r = strdup_or_null(src->label, &dest->label);
+ r = strdup_to(&dest->label, src->label);
if (r < 0)
return r;
}
- r = strdup_or_null(src->netlabel, &dest->netlabel);
+ r = strdup_to(&dest->netlabel, src->netlabel);
if (r < 0)
return r;
} else
dest->metrics_set = NULL;
- return strdup_or_null(src->tcp_congestion_control_algo, &dest->tcp_congestion_control_algo);
+ return strdup_to(&dest->tcp_congestion_control_algo, src->tcp_congestion_control_algo);
}
void route_metric_hash_func(const RouteMetric *metric, struct siphash *state) {
/* unset pointer copied in the above. */
dest->ifname = NULL;
- return strdup_or_null(src->ifindex > 0 ? NULL : src->ifname, &dest->ifname);
+ return strdup_to(&dest->ifname, src->ifindex > 0 ? NULL : src->ifname);
}
static int route_nexthop_dup(const RouteNextHop *src, RouteNextHop **ret) {