summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-netlink/netlink-message.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2019-09-23 03:48:50 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-10-15 01:57:19 +0900
commit59d4103fd545b23ce97973a1ecd0a1db8bc8fb82 (patch)
treecf6d69cd221bc7481011806be97631bb92235ef7 /src/libsystemd/sd-netlink/netlink-message.c
parent6bf8e24bad8bd001d8587d7922842341c32888c2 (diff)
downloadsystemd-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.c26
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;