Add the platform to the game controller mapping so it can be read back in without changes Fixes https://github.com/libsdl-org/SDL/issues/4848
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c
index d65439b..37f6d18 100644
--- a/src/joystick/SDL_gamecontroller.c
+++ b/src/joystick/SDL_gamecontroller.c
@@ -1531,16 +1531,17 @@ SDL_GameControllerMappingForIndex(int mapping_index)
char *pMappingString;
char pchGUID[33];
size_t needed;
+ const char *platform = SDL_GetPlatform();
SDL_JoystickGetGUIDString(mapping->guid, pchGUID, sizeof(pchGUID));
- /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
- needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
+ /* allocate enough memory for GUID + ',' + name + ',' + mapping + platform:PLATFORM + \0 */
+ needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + SDL_strlen(SDL_CONTROLLER_PLATFORM_FIELD) + SDL_strlen(platform) + 1;
pMappingString = SDL_malloc(needed);
if (!pMappingString) {
SDL_OutOfMemory();
return NULL;
}
- SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
+ SDL_snprintf(pMappingString, needed, "%s,%s,%s%s%s", pchGUID, mapping->name, mapping->mapping, SDL_CONTROLLER_PLATFORM_FIELD, platform);
return pMappingString;
}
--mapping_index;
@@ -1559,15 +1560,17 @@ SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
if (mapping) {
char pchGUID[33];
size_t needed;
+ const char *platform = SDL_GetPlatform();
+
SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID));
- /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
- needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
+ /* allocate enough memory for GUID + ',' + name + ',' + mapping + platform:PLATFORM + \0 */
+ needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + SDL_strlen(SDL_CONTROLLER_PLATFORM_FIELD) + SDL_strlen(platform) + 1;
pMappingString = SDL_malloc(needed);
if (!pMappingString) {
SDL_OutOfMemory();
return NULL;
}
- SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
+ SDL_snprintf(pMappingString, needed, "%s,%s,%s%s%s", pchGUID, mapping->name, mapping->mapping, SDL_CONTROLLER_PLATFORM_FIELD, platform);
}
return pMappingString;
}