diff options
Diffstat (limited to 'libgamepad_open_device.c')
-rw-r--r-- | libgamepad_open_device.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/libgamepad_open_device.c b/libgamepad_open_device.c index 87868cb..cce0133 100644 --- a/libgamepad_open_device.c +++ b/libgamepad_open_device.c @@ -8,6 +8,7 @@ libgamepad_open_device(struct libgamepad_device *devicep, int dirfd, const char int err; unsigned int i; uint16_t n; + struct input_id id; devicep->fd = dirfd; devicep->close_fd = 0; @@ -25,23 +26,31 @@ libgamepad_open_device(struct libgamepad_device *devicep, int dirfd, const char devicep->close_fd = 1; } - err = -libevdev_new_from_fd(devicep->fd, &devicep->dev); - if (err > 0) { + if (ioctl(devicep->fd, EVIOCGID, &id)) { if (devicep->close_fd) { close(devicep->fd); devicep->close_fd = 0; } - errno = err; + return -1; + } + + err = libevdev_new_from_fd(devicep->fd, &devicep->dev); + if (err < 0) { + if (devicep->close_fd) { + close(devicep->fd); + devicep->close_fd = 0; + } + errno = -err; return -1; } devicep->name = libevdev_get_name(devicep->dev); devicep->unique_id = libevdev_get_uniq(devicep->dev); devicep->physical_location = libevdev_get_phys(devicep->dev); - devicep->bus_type = libevdev_get_id_bustype(devicep->dev); - devicep->vendor = libevdev_get_id_vendor(devicep->dev); - devicep->product = libevdev_get_id_product(devicep->dev); - devicep->version = libevdev_get_id_version(devicep->dev); + devicep->bus_type = (unsigned int)id.bustype; + devicep->vendor = (unsigned int)id.vendor; + devicep->product = (unsigned int)id.product; + devicep->version = (unsigned int)id.version; devicep->nbuttons = 0; for (i = 0; i < KEY_CNT; i++) { |