udev-util: add wrapper for sd_device_get_property_value()

... that allows to pass additional properties to fall back to.
This commit is contained in:
David Tardon
2023-11-13 16:11:41 +01:00
parent aa78d138ed
commit f20ae7dbdf
2 changed files with 34 additions and 0 deletions

View File

@@ -410,3 +410,30 @@ int device_get_model_string(sd_device *device, const char **ret) {
return -ENOENT;
}
int device_get_property_value_with_fallback(
sd_device *device,
const char *prop,
Hashmap *extra_props,
const char **ret) {
const char *value;
int r;
assert(device);
assert(prop);
assert(ret);
r = sd_device_get_property_value(device, prop, &value);
if (r < 0) {
if (r != -ENOENT)
return r;
value = hashmap_get(extra_props, prop);
if (!value)
return -ENOENT;
}
*ret = value;
return 1;
}

View File

@@ -3,6 +3,7 @@
#include "sd-device.h"
#include "hashmap.h"
#include "time-util.h"
int udev_set_max_log_level(char *str);
@@ -25,3 +26,9 @@ bool udev_available(void);
int device_get_vendor_string(sd_device *device, const char **ret);
int device_get_model_string(sd_device *device, const char **ret);
int device_get_property_value_with_fallback(
sd_device *device,
const char *prop,
Hashmap *extra_props,
const char **ret);