]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: introduce device_get_property_int()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 9 Jan 2023 07:44:11 +0000 (16:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 10 Jan 2023 05:25:20 +0000 (14:25 +0900)
src/libsystemd/sd-device/device-private.h
src/libsystemd/sd-device/sd-device.c

index e57b74ba24496cc49cf02de107ff8119de6b51ab..d9a519a4d98f225ac13701e4c2e291c8681a3b9e 100644 (file)
@@ -18,6 +18,7 @@ int device_new_from_strv(sd_device **ret, char **strv);
 int device_opendir(sd_device *device, const char *subdir, DIR **ret);
 
 int device_get_property_bool(sd_device *device, const char *key);
+int device_get_property_int(sd_device *device, const char *key, int *ret);
 int device_get_sysattr_int(sd_device *device, const char *sysattr, int *ret_value);
 int device_get_sysattr_unsigned(sd_device *device, const char *sysattr, unsigned *ret_value);
 int device_get_sysattr_bool(sd_device *device, const char *sysattr);
index f8a320dddaad529a1864bfcedade2e6ebc5d6ab2..c3160b04bb7e44e4a791fe9175ee4d2727743551 100644 (file)
@@ -2185,6 +2185,26 @@ int device_get_property_bool(sd_device *device, const char *key) {
         return parse_boolean(value);
 }
 
+int device_get_property_int(sd_device *device, const char *key, int *ret) {
+        const char *value;
+        int r, v;
+
+        assert(device);
+        assert(key);
+
+        r = sd_device_get_property_value(device, key, &value);
+        if (r < 0)
+                return r;
+
+        r = safe_atoi(value, &v);
+        if (r < 0)
+                return r;
+
+        if (ret)
+                *ret = v;
+        return 0;
+}
+
 _public_ int sd_device_get_trigger_uuid(sd_device *device, sd_id128_t *ret) {
         const char *s;
         sd_id128_t id;