summaryrefslogtreecommitdiff
path: root/src/libudev/libudev-device.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-01-26 14:45:12 +0100
committerAnthony G. Basile <blueness@gentoo.org>2015-02-08 11:38:43 -0500
commitd868c5f724b38a638954f972badab3f632bd8da4 (patch)
tree7e9e9c0df598cec880563ec8787f5236bcfb10e2 /src/libudev/libudev-device.c
parent21212e522478551f3d256619a2efe2b885ad0948 (diff)
libudev: monitor - move nulstr parsing to libudev-device
Hide the details a bit. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/libudev/libudev-device.c')
-rw-r--r--src/libudev/libudev-device.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c
index 24c8d3b02c..32c80cc9ec 100644
--- a/src/libudev/libudev-device.c
+++ b/src/libudev/libudev-device.c
@@ -1943,3 +1943,48 @@ struct udev_device *udev_device_shallow_clone(struct udev_device *old_device)
return device;
}
+
+struct udev_device *udev_device_new_from_nulstr(struct udev *udev, char *nulstr, ssize_t buflen) {
+ struct udev_device *device;
+ ssize_t bufpos = 0;
+
+ if (nulstr == NULL || buflen <= 0) {
+ errno = EINVAL;
+
+ return NULL;
+ }
+
+ device = udev_device_new(udev);
+ if (!device) {
+ errno = ENOMEM;
+
+ return NULL;
+ }
+
+ udev_device_set_info_loaded(device);
+
+ while (bufpos < buflen) {
+ char *key;
+ size_t keylen;
+
+ key = nulstr + bufpos;
+ keylen = strlen(key);
+ if (keylen == 0)
+ break;
+
+ bufpos += keylen + 1;
+ udev_device_add_property_from_string_parse(device, key);
+ }
+
+ if (udev_device_add_property_from_string_parse_finish(device) < 0) {
+ log_debug("missing values, invalid device");
+
+ udev_device_unref(device);
+
+ errno = EINVAL;
+
+ return NULL;
+ }
+
+ return device;
+}