/* Return the SDL_Joystick associated with a player index.  */
SDL_Joystick* SDL_JoystickFromPlayerIndex(int player_index)
/* Return the SDL_Joystick associated with a player index.  */
SDL_Joystick* SDL_JoystickFromPlayerIndex(int player_index)
{
    SDL_JoystickID instance_id;
    SDL_Joystick *joystick;
    SDL_LockJoysticks();
    instance_id = SDL_GetJoystickIDForPlayerIndex(player_index);
    for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
        if (joystick->instance_id == instance_id) {
            break;
        }
    }
    SDL_UnlockJoysticks();
    return joystick;
}