From 8fbdeb3fe32a7346d868d05d18ea7c2196b8d35f Mon Sep 17 00:00:00 2001 From: illiliti Date: Wed, 8 Jul 2020 17:07:06 +0300 Subject: [PATCH] fix udev_device_get_sysname --- udev_device.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/udev_device.c b/udev_device.c index ddda8fb..61f2e39 100644 --- a/udev_device.c +++ b/udev_device.c @@ -32,12 +32,21 @@ UDEV_EXPORT const char *udev_device_get_syspath(struct udev_device *udev_device) UDEV_EXPORT const char *udev_device_get_sysname(struct udev_device *udev_device) { + const char *sysname; + if (!udev_device) { return NULL; } - // TODO retrieve sysname from DEVPATH if DEVNANE is NULL - return udev_device_get_property_value(udev_device, "DEVNAME"); + if ((sysname = udev_device_get_property_value(udev_device, "DEVNAME"))) { + return sysname; + } + + if ((sysname = udev_device_get_devpath(udev_device))) { + return strrchr(sysname, '/') + 1; + } + + return NULL; } UDEV_EXPORT const char *udev_device_get_sysnum(struct udev_device *udev_device)