sd-device: add device_get_property_uint() helper

This is just like device_get_property_int() but operates on unsigned
ints.
This commit is contained in:
Lennart Poettering
2025-10-22 22:56:01 +02:00
parent d62ab43fd0
commit b09ea23978
2 changed files with 22 additions and 0 deletions
@@ -14,6 +14,7 @@ int device_opendir(sd_device *device, const char *subdir, DIR **ret);
int device_get_sysnum_unsigned(sd_device *device, unsigned *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_property_uint(sd_device *device, const char *key, unsigned *ret);
int device_get_ifname(sd_device *device, const char **ret);
int device_get_sysattr_int(sd_device *device, const char *sysattr, int *ret_value);
int device_get_sysattr_unsigned_full(sd_device *device, const char *sysattr, unsigned base, unsigned *ret_value);
+21
View File
@@ -2319,6 +2319,27 @@ int device_get_property_int(sd_device *device, const char *key, int *ret) {
return 0;
}
int device_get_property_uint(sd_device *device, const char *key, unsigned *ret) {
const char *value;
int r;
assert(device);
assert(key);
r = sd_device_get_property_value(device, key, &value);
if (r < 0)
return r;
unsigned v;
r = safe_atou(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;