diff --git a/configuration.c b/configuration.c index 256703e10f4..18663c1db45 100644 --- a/configuration.c +++ b/configuration.c @@ -1481,6 +1481,7 @@ bool config_overlay_enable_default(void) static struct config_array_setting *populate_settings_array( settings_t *settings, int *size) { + unsigned i = 0; unsigned count = 0; struct config_array_setting *tmp = (struct config_array_setting*)calloc(1, (*size + 1) * sizeof(struct config_array_setting)); @@ -1511,22 +1512,23 @@ static struct config_array_setting *populate_settings_array( SETTING_ARRAY("input_android_physical_keyboard", settings->arrays.input_android_physical_keyboard, false, NULL, true); #endif - SETTING_ARRAY("input_player1_reserved_device", settings->arrays.input_reserved_devices[0], false, NULL, true); - SETTING_ARRAY("input_player2_reserved_device", settings->arrays.input_reserved_devices[1], false, NULL, true); - SETTING_ARRAY("input_player3_reserved_device", settings->arrays.input_reserved_devices[2], false, NULL, true); - SETTING_ARRAY("input_player4_reserved_device", settings->arrays.input_reserved_devices[3], false, NULL, true); - SETTING_ARRAY("input_player5_reserved_device", settings->arrays.input_reserved_devices[4], false, NULL, true); - SETTING_ARRAY("input_player6_reserved_device", settings->arrays.input_reserved_devices[5], false, NULL, true); - SETTING_ARRAY("input_player7_reserved_device", settings->arrays.input_reserved_devices[6], false, NULL, true); - SETTING_ARRAY("input_player8_reserved_device", settings->arrays.input_reserved_devices[7], false, NULL, true); - SETTING_ARRAY("input_player9_reserved_device", settings->arrays.input_reserved_devices[8], false, NULL, true); - SETTING_ARRAY("input_player10_reserved_device", settings->arrays.input_reserved_devices[9], false, NULL, true); - SETTING_ARRAY("input_player11_reserved_device", settings->arrays.input_reserved_devices[10], false, NULL, true); - SETTING_ARRAY("input_player12_reserved_device", settings->arrays.input_reserved_devices[11], false, NULL, true); - SETTING_ARRAY("input_player13_reserved_device", settings->arrays.input_reserved_devices[12], false, NULL, true); - SETTING_ARRAY("input_player14_reserved_device", settings->arrays.input_reserved_devices[13], false, NULL, true); - SETTING_ARRAY("input_player15_reserved_device", settings->arrays.input_reserved_devices[14], false, NULL, true); - SETTING_ARRAY("input_player16_reserved_device", settings->arrays.input_reserved_devices[15], false, NULL, true); + for (i = 0; i < MAX_USERS; i++) + { + size_t _len; + char formatted_number[4]; + char prefix[16]; + char key[32]; + + formatted_number[0] = '\0'; + + snprintf(formatted_number, sizeof(formatted_number), "%u", i + 1); + _len = strlcpy(prefix, "input_player", sizeof(prefix)); + strlcpy(prefix + _len, formatted_number, sizeof(prefix) - _len); + _len = strlcpy(key, prefix, sizeof(key)); + strlcpy(key + _len, "_reserved_device", sizeof(key) - _len); + + SETTING_ARRAY(strdup(key), settings->arrays.input_reserved_devices[i], false, NULL, true); + } #ifdef HAVE_MENU SETTING_ARRAY("menu_driver", settings->arrays.menu_driver, false, NULL, true);