const char *udev_device_get_driver(struct udev_device *udev_device)
{
+ char driver[NAME_SIZE];
+
if (udev_device == NULL)
return NULL;
+ if (udev_device->driver != NULL)
+ return udev_device->driver;
+ if (util_get_sys_driver(udev_device->udev, udev_device->devpath, driver, sizeof(driver)) < 2)
+ return NULL;
+ udev_device->driver = strdup(driver);
return udev_device->driver;
}
#include "libudev-private.h"
#include "../udev.h"
-ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size)
+static ssize_t get_sys_link(struct udev *udev, const char *slink, const char *devpath, char *subsystem, size_t size)
{
char path[PATH_SIZE];
ssize_t len;
strlcpy(path, udev_get_sys_path(udev), sizeof(path));
strlcat(path, devpath, sizeof(path));
- strlcat(path, "/subsystem", sizeof(path));
+ strlcat(path, "/", sizeof(path));
+ strlcat(path, slink, sizeof(path));
len = readlink(path, path, sizeof(path));
if (len < 0 || len >= (ssize_t) sizeof(path))
return -1;
pos = &pos[1];
return strlcpy(subsystem, pos, size);
}
+
+ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size)
+{
+ return get_sys_link(udev, "subsystem", devpath, subsystem, size);
+}
+
+ssize_t util_get_sys_driver(struct udev *udev, const char *devpath, char *driver, size_t size)
+{
+ return get_sys_link(udev, "driver", devpath, driver, size);
+}
+
printf("devpath: '%s'\n", str);
str = udev_device_get_subsystem(device);
printf("subsystem: '%s'\n", str);
+ str = udev_device_get_driver(device);
+ printf("driver: '%s'\n", str);
str = udev_device_get_syspath(device);
printf("syspath: '%s'\n", str);
str = udev_device_get_devname(device);