Bruno Jesus : dinput: Use a helper to read information files for the js device.

Alexandre Julliard julliard at winehq.org
Wed Aug 17 10:24:24 CDT 2016


Module: wine
Branch: master
Commit: 7439f7948c417905028aa82685b1613b77f5cf59
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=7439f7948c417905028aa82685b1613b77f5cf59

Author: Bruno Jesus <00cpxxx at gmail.com>
Date:   Tue Aug 16 22:23:45 2016 -0300

dinput: Use a helper to read information files for the js device.

Signed-off-by: Bruno Jesus <00cpxxx at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dinput/joystick_linux.c | 54 ++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index 20e2573..f7061d5 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -142,6 +142,30 @@ static struct JoyDev *joystick_devices;
 
 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface);
 
+#define SYS_PATH_FORMAT "/sys/class/input/js%d/device/id/%s"
+static BOOL read_sys_id_variable(int index, const char *property, WORD *value)
+{
+    char sys_path[sizeof(SYS_PATH_FORMAT) + 16], id_str[5];
+    int sys_fd;
+    BOOL ret = FALSE;
+
+    sprintf(sys_path, SYS_PATH_FORMAT, index, property);
+    sys_fd = open(sys_path, O_RDONLY);
+    if (sys_fd > 0)
+    {
+        if (read(sys_fd, id_str, 4) == 4)
+        {
+            id_str[4] = '\0';
+            *value = strtol(id_str, NULL, 16);
+            ret = TRUE;
+        }
+
+        close(sys_fd);
+    }
+    return ret;
+}
+#undef SYS_PATH_FORMAT
+
 static INT find_joystick_devices(void)
 {
     INT i;
@@ -151,10 +175,9 @@ static INT find_joystick_devices(void)
     joystick_devices_count = 0;
     for (i = 0; i < MAX_JOYSTICKS; i++)
     {
-        int fd, sys_fd;
+        int fd;
         struct JoyDev joydev, *new_joydevs;
         BYTE axes_map[ABS_MAX + 1];
-        char sys_path[sizeof("/sys/class/input/js/device/id/product") + 10], id_str[5];
 
         snprintf(joydev.device, sizeof(joydev.device), "%s%d", JOYDEV_NEW, i);
         if ((fd = open(joydev.device, O_RDONLY)) < 0)
@@ -225,31 +248,8 @@ static INT find_joystick_devices(void)
         joydev.vendor_id  = 0;
         joydev.product_id = 0;
 
-        sprintf(sys_path, "/sys/class/input/js%d/device/id/vendor", i);
-        sys_fd = open(sys_path, O_RDONLY);
-        if (sys_fd > 0)
-        {
-            if (read(sys_fd, id_str, 4) == 4)
-            {
-                id_str[4] = '\0';
-                joydev.vendor_id = strtol(id_str, NULL, 16);
-            }
-
-            close(sys_fd);
-        }
-
-        sprintf(sys_path, "/sys/class/input/js%d/device/id/product", i);
-        sys_fd = open(sys_path, O_RDONLY);
-        if (sys_fd > 0)
-        {
-            if (read(sys_fd, id_str, 4) == 4)
-            {
-                id_str[4] = '\0';
-                joydev.product_id = strtol(id_str, NULL, 16);
-            }
-
-            close(sys_fd);
-        }
+        read_sys_id_variable(i, "vendor", &joydev.vendor_id);
+        read_sys_id_variable(i, "product", &joydev.product_id);
 
         if (joydev.vendor_id == 0 || joydev.product_id == 0)
         {




More information about the wine-cvs mailing list