]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-netlink: shorten sd_netlink_message_read_string_strdup() a bit
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 10 Oct 2024 03:43:57 +0000 (12:43 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 10 Oct 2024 17:38:16 +0000 (02:38 +0900)
src/libsystemd/sd-netlink/netlink-message.c

index f66733414c745404f6dc55700bb44bb01af01a25..e064c53486e9ac8040446818ffbe6954f45bcb23 100644 (file)
@@ -800,30 +800,16 @@ int sd_netlink_message_read_data(sd_netlink_message *m, uint16_t attr_type, size
 }
 
 int sd_netlink_message_read_string_strdup(sd_netlink_message *m, uint16_t attr_type, char **ret) {
-        void *attr_data;
+        const char *s;
         int r;
 
         assert_return(m, -EINVAL);
 
-        r = message_attribute_has_type(m, NULL, attr_type, NETLINK_TYPE_STRING);
+        r = sd_netlink_message_read_string(m, attr_type, &s);
         if (r < 0)
                 return r;
 
-        r = netlink_message_read_internal(m, attr_type, &attr_data, NULL);
-        if (r < 0)
-                return r;
-
-        if (ret) {
-                char *str;
-
-                str = strndup(attr_data, r);
-                if (!str)
-                        return -ENOMEM;
-
-                *ret = str;
-        }
-
-        return 0;
+        return strdup_to(ret, s);
 }
 
 int sd_netlink_message_read_string(sd_netlink_message *m, uint16_t attr_type, const char **ret) {