From: Yu Watanabe Date: Tue, 21 Sep 2021 17:17:11 +0000 (+0900) Subject: sd-netlink: introduce sd_netlink_message_read_data_suffix0() X-Git-Tag: v250-rc1~599^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a1d2ae065bab27bc2f977691eff9997be6550b38;p=thirdparty%2Fsystemd.git sd-netlink: introduce sd_netlink_message_read_data_suffix0() --- diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c index 27c7910566e..874fffe9d93 100644 --- a/src/libsystemd/sd-netlink/netlink-message.c +++ b/src/libsystemd/sd-netlink/netlink-message.c @@ -776,6 +776,32 @@ int sd_netlink_message_read_data(sd_netlink_message *m, unsigned short type, siz return r; } +int sd_netlink_message_read_data_suffix0(sd_netlink_message *m, unsigned short type, size_t *ret_size, void **ret_data) { + void *attr_data; + int r; + + assert_return(m, -EINVAL); + + r = netlink_message_read_internal(m, type, &attr_data, NULL); + if (r < 0) + return r; + + if (ret_data) { + void *data; + + data = memdup_suffix0(attr_data, r); + if (!data) + return -ENOMEM; + + *ret_data = data; + } + + if (ret_size) + *ret_size = r; + + return r; +} + int sd_netlink_message_read_string_strdup(sd_netlink_message *m, unsigned short type, char **data) { void *attr_data; int r; diff --git a/src/systemd/sd-netlink.h b/src/systemd/sd-netlink.h index ee1b32fddb8..fdf802041a9 100644 --- a/src/systemd/sd-netlink.h +++ b/src/systemd/sd-netlink.h @@ -95,6 +95,7 @@ int sd_netlink_message_close_container(sd_netlink_message *m); int sd_netlink_message_read(sd_netlink_message *m, unsigned short type, size_t size, void *data); int sd_netlink_message_read_data(sd_netlink_message *m, unsigned short type, size_t *ret_size, void **ret_data); +int sd_netlink_message_read_data_suffix0(sd_netlink_message *m, unsigned short type, size_t *ret_size, void **ret_data); int sd_netlink_message_read_string_strdup(sd_netlink_message *m, unsigned short type, char **data); int sd_netlink_message_read_string(sd_netlink_message *m, unsigned short type, const char **data); int sd_netlink_message_read_strv(sd_netlink_message *m, unsigned short container_type, unsigned short type_id, char ***ret);