udev-util: add generic device_get_{vendor,model}_string() helpers

We chck the same props in various places, add a single implementation of
a call to inquire this.
This commit is contained in:
Lennart Poettering
2023-11-13 16:24:17 +01:00
parent 7e91c97aff
commit 3cc7a9fd25
7 changed files with 49 additions and 41 deletions
+28
View File
@@ -382,3 +382,31 @@ bool udev_available(void) {
return (cache = (path_is_read_only_fs("/sys/") <= 0));
}
int device_get_vendor_string(sd_device *device, const char **ret) {
int r;
assert(device);
FOREACH_STRING(field, "ID_VENDOR_FROM_DATABASE", "ID_VENDOR") {
r = sd_device_get_property_value(device, field, ret);
if (r != -ENOENT)
return r;
}
return -ENOENT;
}
int device_get_model_string(sd_device *device, const char **ret) {
int r;
assert(device);
FOREACH_STRING(field, "ID_MODEL_FROM_DATABASE", "ID_MODEL") {
r = sd_device_get_property_value(device, field, ret);
if (r != -ENOENT)
return r;
}
return -ENOENT;
}
+3
View File
@@ -22,3 +22,6 @@ size_t udev_replace_chars(char *str, const char *allow);
int udev_queue_is_empty(void);
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);