SDL: gamepad: Accept older 'Mac OS X' mappings on macOS (3cf15)

From 3cf15dc222de5ed8d12cc79556c4c18daecb3278 Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Thu, 29 Jan 2026 18:08:06 -0600
Subject: [PATCH] gamepad: Accept older 'Mac OS X' mappings on macOS

(cherry picked from commit e3c9ec7b672de2618d40a276952033094b281567)
---
 src/joystick/SDL_gamepad.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c
index 4faf31beacfec..09f11e133a990 100644
--- a/src/joystick/SDL_gamepad.c
+++ b/src/joystick/SDL_gamepad.c
@@ -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++;
                 }
             }
         }