mirror of
https://github.com/systemd/systemd
synced 2024-10-02 22:37:25 +00:00
Replace strdup_or_null() by strdup_to()
I didn't know that this helper existed… It is very similar to strdup_to_full(), but all callers can actually be replaced by strdup_to(), which has more fitting semantics.
This commit is contained in:
parent
f174b294f6
commit
6a705f1234
|
@ -303,25 +303,4 @@ bool version_is_valid_versionspec(const char *s);
|
|||
|
||||
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);
|
||||
|
|
|
@ -5338,7 +5338,7 @@ int unit_set_exec_params(Unit *u, ExecParameters *p) {
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -498,13 +498,8 @@ static int mandatory_mount_drop_unapplicable_options(
|
|||
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);
|
||||
|
|
|
@ -151,37 +151,37 @@ static int context_copy(const Context *source, Context *ret) {
|
|||
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);
|
||||
|
|
|
@ -613,12 +613,12 @@ int address_dup(const Address *src, Address **ret) {
|
|||
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;
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ int route_metric_copy(const RouteMetric *src, RouteMetric *dest) {
|
|||
} 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) {
|
||||
|
|
|
@ -218,7 +218,7 @@ static int route_nexthop_copy(const RouteNextHop *src, RouteNextHop *dest) {
|
|||
/* 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) {
|
||||
|
|
Loading…
Reference in a new issue