diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-09-23 03:48:50 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-10-15 01:57:19 +0900 |
commit | 59d4103fd545b23ce97973a1ecd0a1db8bc8fb82 (patch) | |
tree | cf6d69cd221bc7481011806be97631bb92235ef7 /src/libsystemd/sd-netlink/netlink-message.c | |
parent | 6bf8e24bad8bd001d8587d7922842341c32888c2 (diff) | |
download | systemd-59d4103fd545b23ce97973a1ecd0a1db8bc8fb82.tar.gz |
sd-netlink: introduce sd_netlink_message_read_string_strdup()
Diffstat (limited to 'src/libsystemd/sd-netlink/netlink-message.c')
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-message.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c index e1395c6bde..a30911b404 100644 --- a/src/libsystemd/sd-netlink/netlink-message.c +++ b/src/libsystemd/sd-netlink/netlink-message.c @@ -618,6 +618,32 @@ int sd_netlink_message_read(sd_netlink_message *m, unsigned short type, size_t s return r; } +int sd_netlink_message_read_string_strdup(sd_netlink_message *m, unsigned short type, char **data) { + void *attr_data; + char *str; + int r; + + assert_return(m, -EINVAL); + + r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_STRING); + if (r < 0) + return r; + + r = netlink_message_read_internal(m, type, &attr_data, NULL); + if (r < 0) + return r; + + if (data) { + str = strndup(attr_data, r); + if (!str) + return -ENOMEM; + + *data = str; + } + + return 0; +} + int sd_netlink_message_read_string(sd_netlink_message *m, unsigned short type, const char **data) { int r; void *attr_data; |