src/joystick/bsd/SDL_sysjoystick.c
changeset 10187 1f0f8c95531d
parent 9998 f67cf37e9cd4
child 10617 346c02ff71b6
equal deleted inserted replaced
10186:6c8e53149f0c 10187:1f0f8c95531d
   177     for (i = 0; i < MAX_UHID_JOYS; i++) {
   177     for (i = 0; i < MAX_UHID_JOYS; i++) {
   178         SDL_Joystick nj;
   178         SDL_Joystick nj;
   179 
   179 
   180         SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i);
   180         SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i);
   181 
   181 
   182         joynames[SDL_SYS_numjoysticks] = strdup(s);
   182         joynames[SDL_SYS_numjoysticks] = SDL_strdup(s);
   183 
   183 
   184         if (SDL_SYS_JoystickOpen(&nj, SDL_SYS_numjoysticks) == 0) {
   184         if (SDL_SYS_JoystickOpen(&nj, SDL_SYS_numjoysticks) == 0) {
   185             SDL_SYS_JoystickClose(&nj);
   185             SDL_SYS_JoystickClose(&nj);
   186             SDL_SYS_numjoysticks++;
   186             SDL_SYS_numjoysticks++;
   187         } else {
   187         } else {
   191     }
   191     }
   192     for (i = 0; i < MAX_JOY_JOYS; i++) {
   192     for (i = 0; i < MAX_JOY_JOYS; i++) {
   193         SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i);
   193         SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i);
   194         fd = open(s, O_RDONLY);
   194         fd = open(s, O_RDONLY);
   195         if (fd != -1) {
   195         if (fd != -1) {
   196             joynames[SDL_SYS_numjoysticks++] = strdup(s);
   196             joynames[SDL_SYS_numjoysticks++] = SDL_strdup(s);
   197             close(fd);
   197             close(fd);
   198         }
   198         }
   199     }
   199     }
   200 
   200 
   201     /* Read the default USB HID usage table. */
   201     /* Read the default USB HID usage table. */
   302         close(fd);
   302         close(fd);
   303         return SDL_OutOfMemory();
   303         return SDL_OutOfMemory();
   304     }
   304     }
   305     joy->hwdata = hw;
   305     joy->hwdata = hw;
   306     hw->fd = fd;
   306     hw->fd = fd;
   307     hw->path = strdup(path);
   307     hw->path = SDL_strdup(path);
   308     if (!SDL_strncmp(path, "/dev/joy", 8)) {
   308     if (!SDL_strncmp(path, "/dev/joy", 8)) {
   309         hw->type = BSDJOY_JOY;
   309         hw->type = BSDJOY_JOY;
   310         joy->naxes = 2;
   310         joy->naxes = 2;
   311         joy->nbuttons = 2;
   311         joy->nbuttons = 2;
   312         joy->nhats = 0;
   312         joy->nhats = 0;
   313         joy->nballs = 0;
   313         joy->nballs = 0;
   314         joydevnames[device_index] = strdup("Gameport joystick");
   314         joydevnames[device_index] = SDL_strdup("Gameport joystick");
   315         goto usbend;
   315         goto usbend;
   316     } else {
   316     } else {
   317         hw->type = BSDJOY_UHID;
   317         hw->type = BSDJOY_UHID;
   318     }
   318     }
   319 
   319 
   361             str[i] = UGETW(usd.usd_desc.bString[i]);
   361             str[i] = UGETW(usd.usd_desc.bString[i]);
   362         }
   362         }
   363         str[i] = '\0';
   363         str[i] = '\0';
   364         asprintf(&new_name, "%s @ %s", str, path);
   364         asprintf(&new_name, "%s @ %s", str, path);
   365         if (new_name != NULL) {
   365         if (new_name != NULL) {
   366             free(joydevnames[SDL_SYS_numjoysticks]);
   366             SDL_free(joydevnames[SDL_SYS_numjoysticks]);
   367             joydevnames[SDL_SYS_numjoysticks] = new_name;
   367             joydevnames[SDL_SYS_numjoysticks] = new_name;
   368         }
   368         }
   369     }
   369     }
   370 desc_failed:
   370 desc_failed:
   371 #endif
   371 #endif