diff --git a/README.md b/README.md index e9881b3..3395f06 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ What Works * [x] xorg-server * [x] libinput * [ ] wlroots - partially works. someone reported that mouse doesn't work -* [ ] weston - need implement udev_device_new_from_subsystem_sysname() +* [ ] weston - should work. need test * [ ] kwin - fails to compile for odd reason * [ ] ??? diff --git a/udev_device.c b/udev_device.c index 7cc484a..841fcdd 100644 --- a/udev_device.c +++ b/udev_device.c @@ -514,7 +514,22 @@ UDEV_EXPORT struct udev_device *udev_device_new_from_devnum(struct udev *udev, c UDEV_EXPORT struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname) { - // XXX NOT IMPLEMENTED + char *fmt[] = { "/sys/bus/%s/devices/%s", "/sys/class/%s/%s", NULL }; + char path[PATH_MAX]; + int i; + + if (!udev || !subsystem || !sysname) { + return NULL; + } + + for (i = 0; fmt[i]; i++) { + snprintf(path, sizeof(path), fmt[i], subsystem, sysname); + + if (access(path, R_OK)) { + return udev_device_new_from_syspath(udev, path); + } + } + return NULL; }