diff options
author | Tom Gundersen <teg@jklm.no> | 2015-01-26 14:45:12 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-01-26 14:45:12 +0100 |
commit | 2df959ec3b5128dfe4d9b996dc13b16a8f4c4233 (patch) | |
tree | bc17c582ad342a3f75d34d7e5ff00a1595c4d473 /src/libudev/libudev-device.c | |
parent | 04ef387ea900ff59f801d7bf745f21e644711643 (diff) |
libudev: monitor - move nulstr parsing to libudev-device
Hide the details a bit.
Diffstat (limited to 'src/libudev/libudev-device.c')
-rw-r--r-- | src/libudev/libudev-device.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 08331a2329..6031237762 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -1965,3 +1965,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; +} |