/* Return the SDL_GameController associated with an instance id.  */
SDL_GameController* SDL_GameControllerFromInstanceID(SDL_JoystickID joyid)
/* Return the SDL_GameController associated with an instance id.  */
SDL_GameController* SDL_GameControllerFromInstanceID(SDL_JoystickID joyid)
{
    SDL_GameController *gamecontroller;
    SDL_LockJoysticks();
    gamecontroller = SDL_gamecontrollers;
    while (gamecontroller) {
        if (gamecontroller->joystick->instance_id == joyid) {
            SDL_UnlockJoysticks();
            return gamecontroller;
        }
        gamecontroller = gamecontroller->next;
    }
    SDL_UnlockJoysticks();
    return NULL;
}