X Tutup
Skip to content

Commit 71978a7

Browse files
committed
sd-device: introduce device_add_propertyf()
1 parent b586cbd commit 71978a7

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/libsystemd/sd-device/device-private.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ int device_add_property(sd_device *device, const char *key, const char *value) {
4747
return 0;
4848
}
4949

50+
int device_add_propertyf(sd_device *device, const char *key, const char *format, ...) {
51+
_cleanup_free_ char *value = NULL;
52+
va_list ap;
53+
int r;
54+
55+
assert(device);
56+
assert(key);
57+
58+
if (!format)
59+
return device_add_property(device, key, NULL);
60+
61+
va_start(ap, format);
62+
r = vasprintf(&value, format, ap);
63+
va_end(ap);
64+
65+
if (r < 0)
66+
return -ENOMEM;
67+
68+
return device_add_property(device, key, value);
69+
}
70+
5071
void device_set_devlink_priority(sd_device *device, int priority) {
5172
assert(device);
5273

src/libsystemd/sd-device/device-private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ int device_ensure_usec_initialized(sd_device *device, sd_device *device_old);
3636
int device_add_devlink(sd_device *device, const char *devlink);
3737
bool device_has_devlink(sd_device *device, const char *devlink);
3838
int device_add_property(sd_device *device, const char *property, const char *value);
39+
int device_add_propertyf(sd_device *device, const char *key, const char *format, ...) _printf_(3, 4);
3940
int device_add_tag(sd_device *device, const char *tag, bool both);
4041
void device_remove_tag(sd_device *device, const char *tag);
4142
void device_cleanup_tags(sd_device *device);

0 commit comments

Comments
 (0)
X Tutup