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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user