[PATCH libevdev 3/4] uinput: split uinput device creation into a helper function
Peter Hutterer
peter.hutterer at who-t.net
Thu Apr 7 01:34:47 UTC 2016
No functional changes. This is prep work for supporting the new
UIDEV_DEV_SETUP ioctl.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
libevdev/libevdev-uinput.c | 56 +++++++++++++++++++++++++++++-----------------
1 file changed, 36 insertions(+), 20 deletions(-)
diff --git a/libevdev/libevdev-uinput.c b/libevdev/libevdev-uinput.c
index 1316952..0046607 100644
--- a/libevdev/libevdev-uinput.c
+++ b/libevdev/libevdev-uinput.c
@@ -271,29 +271,12 @@ fetch_syspath_and_devnode(struct libevdev_uinput *uinput_dev)
return uinput_dev->devnode ? 0 : -1;
}
-LIBEVDEV_EXPORT int
-libevdev_uinput_create_from_device(const struct libevdev *dev, int fd, struct libevdev_uinput** uinput_dev)
+static int
+uinput_create(const struct libevdev *dev, int fd,
+ struct libevdev_uinput *new_device)
{
int rc;
struct uinput_user_dev uidev;
- struct libevdev_uinput *new_device;
- int close_fd_on_error = (fd == LIBEVDEV_UINPUT_OPEN_MANAGED);
-
- new_device = alloc_uinput_device(libevdev_get_name(dev));
- if (!new_device)
- return -ENOMEM;
-
- if (fd == LIBEVDEV_UINPUT_OPEN_MANAGED) {
- fd = open("/dev/uinput", O_RDWR|O_CLOEXEC);
- if (fd < 0)
- goto error;
-
- new_device->fd_is_managed = 1;
- } else if (fd < 0) {
- log_bug(NULL, "Invalid fd %d\n", fd);
- errno = EBADF;
- goto error;
- }
memset(&uidev, 0, sizeof(uidev));
@@ -316,6 +299,39 @@ libevdev_uinput_create_from_device(const struct libevdev *dev, int fd, struct li
goto error;
}
+ errno = 0;
+
+error:
+ return -errno;
+}
+
+LIBEVDEV_EXPORT int
+libevdev_uinput_create_from_device(const struct libevdev *dev, int fd, struct libevdev_uinput** uinput_dev)
+{
+ int rc;
+ struct libevdev_uinput *new_device;
+ int close_fd_on_error = (fd == LIBEVDEV_UINPUT_OPEN_MANAGED);
+
+ new_device = alloc_uinput_device(libevdev_get_name(dev));
+ if (!new_device)
+ return -ENOMEM;
+
+ if (fd == LIBEVDEV_UINPUT_OPEN_MANAGED) {
+ fd = open("/dev/uinput", O_RDWR|O_CLOEXEC);
+ if (fd < 0)
+ goto error;
+
+ new_device->fd_is_managed = 1;
+ } else if (fd < 0) {
+ log_bug(NULL, "Invalid fd %d\n", fd);
+ errno = EBADF;
+ goto error;
+ }
+
+ rc = uinput_create(dev, fd, new_device);
+ if (rc != 0)
+ goto error;
+
/* ctime notes time before/after ioctl to help us filter out devices
when traversing /sys/devices/virtual/input to find the device
node.
--
2.5.5
More information about the Input-tools
mailing list