summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-11-19 12:53:29 -0500
committerLennart Poettering <lennart@poettering.net>2016-11-21 23:01:02 +0100
commitef8b0084552e05f28b9132d5dfc75edae164a991 (patch)
tree47481b0265e8f4fcb4ba1758cb701ac505451988
parent640be8806e1ce366b9046a4828889515c98b72f9 (diff)
sd-dhcp-client: use free_and_strdup
This changes the return value a bit: 1 will be returned if the value is changed. But the return value was not documented, and the change should be for the good anyway. Current callers don't care.
-rw-r--r--src/libsystemd-network/sd-dhcp-client.c34
1 files changed, 4 insertions, 30 deletions
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index 9716168c1e..1423264806 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -386,49 +386,23 @@ int sd_dhcp_client_set_hostname(
sd_dhcp_client *client,
const char *hostname) {
- char *new_hostname = NULL;
-
assert_return(client, -EINVAL);
- if (!hostname) {
- client->hostname = mfree(client->hostname);
- return 0;
- }
-
/* Refuse hostnames that neither qualify as DNS nor as Linux hosntames */
- if (!hostname_is_valid(hostname, false) && !dns_name_is_valid(hostname))
+ if (hostname &&
+ !(hostname_is_valid(hostname, false) || dns_name_is_valid(hostname) > 0))
return -EINVAL;
- if (streq_ptr(client->hostname, hostname))
- return 0;
-
- new_hostname = strdup(hostname);
- if (!new_hostname)
- return -ENOMEM;
-
- free(client->hostname);
- client->hostname = new_hostname;
-
- return 0;
+ return free_and_strdup(&client->hostname, hostname);
}
int sd_dhcp_client_set_vendor_class_identifier(
sd_dhcp_client *client,
const char *vci) {
- char *new_vci = NULL;
-
assert_return(client, -EINVAL);
- new_vci = strdup(vci);
- if (!new_vci)
- return -ENOMEM;
-
- free(client->vendor_class_identifier);
-
- client->vendor_class_identifier = new_vci;
-
- return 0;
+ return free_and_strdup(&client->vendor_class_identifier, vci);
}
int sd_dhcp_client_set_client_port(