diff --git a/360/main.c b/360/main.c index 8d202322a3..9595d44a82 100644 --- a/360/main.c +++ b/360/main.c @@ -199,7 +199,11 @@ static void init_settings (bool load_libretro_path) CONFIG_GET_STRING(libretro, "libretro_path"); if(!strcmp(g_settings.libretro, "")) - rarch_manage_libretro_set_first_file("game:\\", ".xex"); + { + const char *first_file = rarch_manage_libretro_set_first_file("game:\\", ".xex"); + if(first_file != NULL) + strlcpy(g_settings.libretro, first_file, sizeof(g_settings.libretro)); + } } #endif diff --git a/console/libretro_mgmt.c b/console/libretro_mgmt.c index 48fdca8f36..798e4ab64f 100644 --- a/console/libretro_mgmt.c +++ b/console/libretro_mgmt.c @@ -102,28 +102,28 @@ bool rarch_manage_libretro_install(const char *full_path, const char *path, cons return return_code; } -void rarch_manage_libretro_set_first_file(const char *libretro_path, const char * exe_ext) +const char * rarch_manage_libretro_set_first_file(const char *libretro_path, const char * exe_ext) { -#ifdef _XBOX - char fname_tmp[PATH_MAX]; -#endif - //We need to set libretro to the first entry in the cores //directory so that it will be saved to the config file char ** dir_list = dir_list_new(libretro_path, exe_ext); + const char * retstr = NULL; + const char * first_exe; + if (!dir_list) { RARCH_ERR("Couldn't read directory.\n"); - return; + goto error; } - const char * first_exe = dir_list[0]; + first_exe = dir_list[0]; if(first_exe) { #ifdef _XBOX + char fname_tmp[PATH_MAX]; fill_pathname_base(fname_tmp, first_exe, sizeof(fname_tmp)); if(strcmp(fname_tmp, "RetroArch-Salamander.xex") == 0) @@ -140,17 +140,17 @@ void rarch_manage_libretro_set_first_file(const char *libretro_path, const char } } - RARCH_LOG("Set first entry in libretro core dir to libretro path: [%s].\n", fname_tmp); - snprintf(g_settings.libretro, sizeof(g_settings.libretro), "game:\\%s", fname_tmp); + retstr = fname_tmp; #else - RARCH_LOG("Set first entry in libretro core dir to libretro path: [%s].\n", first_exe); - strlcpy(g_settings.libretro, first_exe, sizeof(g_settings.libretro)); + retstr = first_exe; #endif - } - else - { - RARCH_ERR("Failed to set first .xex entry to libretro path.\n"); + RARCH_LOG("Set first entry in libretro core dir to libretro path: [%s].\n", retstr); + goto end; } +error: + RARCH_ERR("Failed to set first entry to libretro path.\n"); +end: dir_list_free(dir_list); + return retstr; } diff --git a/console/libretro_mgmt.h b/console/libretro_mgmt.h index 4074af6b68..df354c1547 100644 --- a/console/libretro_mgmt.h +++ b/console/libretro_mgmt.h @@ -20,6 +20,6 @@ #include "../boolean.h" bool rarch_manage_libretro_install(const char *full_path, const char *path, const char *exe_ext); -void rarch_manage_libretro_set_first_file(const char *libretro_path, const char * exe_ext); +const char * rarch_manage_libretro_set_first_file(const char *libretro_path, const char * exe_ext); #endif diff --git a/ps3/main.c b/ps3/main.c index caaf68eba2..b4e4883359 100644 --- a/ps3/main.c +++ b/ps3/main.c @@ -169,7 +169,11 @@ static void init_settings(bool load_libretro_path) CONFIG_GET_STRING(libretro, "libretro_path"); if(!strcmp(g_settings.libretro, "")) - rarch_manage_libretro_set_first_file(LIBRETRO_DIR_PATH, ".SELF"); + { + const char *first_file = rarch_manage_libretro_set_first_file(LIBRETRO_DIR_PATH, ".SELF"); + if(first_file != NULL) + strlcpy(g_settings.libretro, first_file, sizeof(g_settings.libretro)); + } } #endif