diff options
| author | Niclas Zeising <zeising@daemonic.se> | 2020-08-13 12:01:35 +0200 |
|---|---|---|
| committer | Niclas Zeising <zeising@daemonic.se> | 2020-08-14 17:50:56 +0200 |
| commit | 83e446225d3a71f4aea8691d28c5ced763afb360 (patch) | |
| tree | 9dfaf39e4c585e8aba608413081495b1b6b138f6 /libevdev | |
| parent | 153d8d0a5ad6bf2379bd03df6307029180bac0ab (diff) | |
| download | libevdev-83e446225d3a71f4aea8691d28c5ced763afb360.tar.gz | |
uinput: Implement FreeBSD fetch_syspath_and_devnode()
Implement a FreeBSD version of fetch_syspath_and_devnode().
FreeBSD does not have sysfs, so instead fetch the device node directly
as as this matches with what is returned by the UI_GET_SYSNAME ioctl().
Since there is no sysfs, libevdev_uinput.syspath will always be set to NULL.
If the ioctl fail, return -1 from fetch_syspath_and_devnode(), since
there is no other way to figure out the device node path.
Signed-off-by: Niclas Zeising <zeising@daemonic.se>
Diffstat (limited to 'libevdev')
| -rw-r--r-- | libevdev/libevdev-uinput.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libevdev/libevdev-uinput.c b/libevdev/libevdev-uinput.c index 7bbff44..a7a8ad3 100644 --- a/libevdev/libevdev-uinput.c +++ b/libevdev/libevdev-uinput.c @@ -180,6 +180,35 @@ libevdev_uinput_get_fd(const struct libevdev_uinput *uinput_dev) return uinput_dev->fd; } +#ifdef __FreeBSD__ +/* + * FreeBSD does not have anything similar to sysfs. + * Set libevdev_uinput->syspath to NULL unconditionally. + * Look up the device nodes directly instead of via sysfs, as this matches what + * is returned by the UI_GET_SYSNAME ioctl() on FreeBSD. + */ +static int +fetch_syspath_and_devnode(struct libevdev_uinput *uinput_dev) +{ +#define DEV_INPUT_DIR "/dev/input/" + int rc; + char buf[sizeof(DEV_INPUT_DIR) + 64] = DEV_INPUT_DIR; + + rc = ioctl(uinput_dev->fd, + UI_GET_SYSNAME(sizeof(buf) - strlen(DEV_INPUT_DIR)), + &buf[strlen(DEV_INPUT_DIR)]); + if (rc == -1) + return -1; + + uinput_dev->syspath = NULL; + uinput_dev->devnode = strdup(buf); + + return 0; +#undef DEV_INPUT_DIR +} + +#else /* !__FreeBSD__ */ + static int is_event_device(const struct dirent *dent) { return strncmp("event", dent->d_name, 5) == 0; } @@ -291,6 +320,7 @@ fetch_syspath_and_devnode(struct libevdev_uinput *uinput_dev) return uinput_dev->devnode ? 0 : -1; #undef SYS_INPUT_DIR } +#endif /* __FreeBSD__*/ static int uinput_create_write(const struct libevdev *dev, int fd) |
