gamepad: Accept older 'Mac OS X' mappings on macOS

(cherry picked from commit e3c9ec7b67)
This commit is contained in:
Cameron Gutman
2026-01-29 18:08:06 -06:00
parent 38b5ad824d
commit 3cf15dc222

View File

@@ -2360,14 +2360,25 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMapping(SDL_JoystickID instance_id
return mapping;
}
bool SDL_PrivateIsGamepadPlatformMatch(const char *platform, size_t platform_len)
{
#ifdef SDL_PLATFORM_MACOS
// We also accept the older SDL2 platform name for macOS
if (SDL_strncasecmp(platform, "Mac OS X", platform_len) == 0) {
return true;
}
#endif
return SDL_strncasecmp(platform, SDL_GetPlatform(), platform_len) == 0;
}
/*
* Add or update an entry into the Mappings Database
*/
int SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, bool closeio)
{
const char *platform = SDL_GetPlatform();
int gamepads = 0;
char *buf, *line, *line_end, *tmp, *comma, line_platform[64];
char *buf, *line, *line_end, *tmp, *comma, *platform;
size_t db_size;
size_t platform_len;
@@ -2396,13 +2407,11 @@ int SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, bool closeio)
tmp += SDL_GAMEPAD_PLATFORM_FIELD_SIZE;
comma = SDL_strchr(tmp, ',');
if (comma) {
platform_len = comma - tmp + 1;
if (platform_len + 1 < SDL_arraysize(line_platform)) {
SDL_strlcpy(line_platform, tmp, platform_len);
if (SDL_strncasecmp(line_platform, platform, platform_len) == 0 &&
SDL_AddGamepadMapping(line) > 0) {
gamepads++;
}
platform = tmp;
platform_len = comma - platform;
if (SDL_PrivateIsGamepadPlatformMatch(platform, platform_len) &&
SDL_AddGamepadMapping(line) > 0) {
gamepads++;
}
}
}