sd-device: introduce sd_device_set_sysattr_valuef()
This commit is contained in:
parent
f8bff7805e
commit
ea2bc25762
|
@ -732,4 +732,5 @@ global:
|
|||
sd_device_get_current_tag_first;
|
||||
sd_device_get_current_tag_next;
|
||||
sd_device_has_current_tag;
|
||||
sd_device_set_sysattr_valuef;
|
||||
} LIBSYSTEMD_246;
|
||||
|
|
|
@ -1979,3 +1979,26 @@ _public_ int sd_device_set_sysattr_value(sd_device *device, const char *sysattr,
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_device_set_sysattr_valuef(sd_device *device, const char *sysattr, const char *format, ...) {
|
||||
_cleanup_free_ char *value = NULL;
|
||||
va_list ap;
|
||||
int r;
|
||||
|
||||
assert_return(device, -EINVAL);
|
||||
assert_return(sysattr, -EINVAL);
|
||||
|
||||
if (!format) {
|
||||
device_remove_sysattr_value(device, sysattr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
va_start(ap, format);
|
||||
r = vasprintf(&value, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (r < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
return sd_device_set_sysattr_value(device, sysattr, value);
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ int sd_device_get_property_value(sd_device *device, const char *key, const char
|
|||
int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **_value);
|
||||
|
||||
int sd_device_set_sysattr_value(sd_device *device, const char *sysattr, const char *value);
|
||||
int sd_device_set_sysattr_valuef(sd_device *device, const char *sysattr, const char *format, ...) _sd_printf_(3, 4);
|
||||
|
||||
/* device enumerator */
|
||||
|
||||
|
|
Loading…
Reference in New Issue