diff --git a/file.c b/file.c index d4b8acf48e..55a940d6b0 100644 --- a/file.c +++ b/file.c @@ -533,34 +533,38 @@ static bool load_roms(unsigned rom_type, const char **rom_paths, size_t roms) void *rom_buf[MAX_ROMS] = {NULL}; ssize_t rom_len[MAX_ROMS] = {0}; struct retro_game_info info[MAX_ROMS] = {{NULL}}; + char *xml_buf = load_xml_map(g_extern.xml_name); + + FILE *rom_file = NULL; + if (rom_paths[0]) + { + RARCH_LOG("Loading ROM file: %s.\n", rom_paths[0]); + rom_file = fopen(rom_paths[0], "rb"); + } if (!g_extern.system.info.need_fullpath) { - if ((rom_len[0] = read_rom_file(g_extern.rom_file, &rom_buf[0])) == -1) + if ((rom_len[0] = read_rom_file(rom_file, &rom_buf[0])) == -1) { RARCH_ERR("Could not read ROM file.\n"); - return false; + ret = false; + goto end; } - if (g_extern.rom_file) - fclose(g_extern.rom_file); - RARCH_LOG("ROM size: %u bytes.\n", (unsigned)rom_len[0]); } else { - if (!g_extern.rom_file) + if (!rom_file) { RARCH_ERR("Implementation requires a full path to be set, cannot load ROM from stdin. Aborting ...\n"); - return false; + ret = false; + goto end; } - fclose(g_extern.rom_file); RARCH_LOG("ROM loading skipped. Implementation will load it on its own.\n"); } - char *xml_buf = load_xml_map(g_extern.xml_name); - info[0].path = rom_paths[0]; info[0].data = rom_buf[0]; info[0].size = rom_len[0]; @@ -594,6 +598,8 @@ end: for (unsigned i = 0; i < MAX_ROMS; i++) free(rom_buf[i]); free(xml_buf); + if (rom_file) + fclose(rom_file); return ret; } diff --git a/general.h b/general.h index 38275bb9c3..301971ddce 100644 --- a/general.h +++ b/general.h @@ -309,7 +309,6 @@ struct global bool has_justifiers; bool has_multitap; - FILE *rom_file; enum rarch_game_type game_type; uint32_t cart_crc; diff --git a/retroarch.c b/retroarch.c index f5652ac6aa..761159c10b 100644 --- a/retroarch.c +++ b/retroarch.c @@ -718,14 +718,6 @@ static void set_paths(const char *path) { set_basename(path); - RARCH_LOG("Opening file: \"%s\"\n", path); - g_extern.rom_file = fopen(path, "rb"); - if (g_extern.rom_file == NULL) - { - RARCH_ERR("Could not open file: \"%s\"\n", path); - rarch_fail(1, "set_paths()"); - } - if (!g_extern.has_set_save_path) fill_pathname_noext(g_extern.savefile_name_srm, g_extern.basename, ".srm", sizeof(g_extern.savefile_name_srm)); if (!g_extern.has_set_state_path)