diff --git a/frontend/drivers/platform_wii.c b/frontend/drivers/platform_wii.c index 9a6a2c4bd7..9c3ce4bc3f 100644 --- a/frontend/drivers/platform_wii.c +++ b/frontend/drivers/platform_wii.c @@ -27,7 +27,6 @@ #include #include -#include #include #include @@ -49,9 +48,10 @@ char gx_rom_path[PATH_MAX_LENGTH]; static void dol_copy_argv_path(const char *dolpath, const char *argpath) { char tmp[PATH_MAX_LENGTH]; - size_t t_len, len = 0; + size_t t_len; struct __argv *argv = (struct __argv *)ARGS_ADDR; char *cmdline = NULL; + size_t len = 0; memset(ARGS_ADDR, 0, sizeof(struct __argv)); @@ -115,13 +115,13 @@ static void dol_copy_argv_path(const char *dolpath, const char *argpath) * heap memory and are restricted to the stack only. */ void system_exec_wii(const char *_path, bool should_load_game) { - size_t booter_size; - ssize_t length; + FILE *fp; + size_t size, booter_size; + void *dol; char path[PATH_MAX_LENGTH]; char game_path[PATH_MAX_LENGTH]; - void *dol = NULL; #ifndef IS_SALAMANDER - global_t *global = global_get_ptr(); + global_t *global = global_get_ptr(); bool original_verbose = global->verbosity; global->verbosity = true; #endif @@ -139,12 +139,30 @@ void system_exec_wii(const char *_path, bool should_load_game) } RARCH_LOG("Attempt to load executable: [%s]\n", path); - if (retro_read_file(path, dol, &length) != 1) + + fp = fopen(path, "rb"); + if (fp == NULL) { RARCH_ERR("Could not open DOL file %s.\n", path); goto exit; } + fseek(fp, 0, SEEK_END); + size = ftell(fp); + fseek(fp, 0, SEEK_SET); + + /* try to allocate a buffer for it. if we can't, fail. */ + dol = malloc(size); + if (!dol) + { + RARCH_ERR("Could not execute DOL file %s.\n", path); + fclose(fp); + goto exit; + } + + fread(dol, 1, size, fp); + fclose(fp); + fatUnmount("carda:"); fatUnmount("cardb:"); fatUnmount("sd:"); @@ -153,8 +171,8 @@ void system_exec_wii(const char *_path, bool should_load_game) __io_usbstorage.shutdown(); /* don't use memcpy, there might be an overlap. */ - memmove(EXECUTE_ADDR, dol, length); - DCFlushRange(EXECUTE_ADDR, length); + memmove(EXECUTE_ADDR, dol, size); + DCFlushRange(EXECUTE_ADDR, size); dol_copy_argv_path(path, should_load_game ? game_path : NULL);