diff --git a/command_event.c b/command_event.c index ff309ff04d..cafe2122e6 100644 --- a/command_event.c +++ b/command_event.c @@ -1707,12 +1707,7 @@ bool event_command(enum event_command cmd) global->subsystem_fullpaths = NULL; break; case EVENT_CMD_LOG_FILE_DEINIT: - if (!global) - break; - - if (global->log_file && global->log_file != stderr) - fclose(global->log_file); - global->log_file = NULL; + retro_main_log_file_deinit(); break; case EVENT_CMD_DISK_EJECT_TOGGLE: if (info && info->disk_control.get_num_images) diff --git a/frontend/drivers/platform_ctr.c b/frontend/drivers/platform_ctr.c index 5062c16e9b..df1ccb250e 100644 --- a/frontend/drivers/platform_ctr.c +++ b/frontend/drivers/platform_ctr.c @@ -49,8 +49,7 @@ static void frontend_ctr_get_environment_settings(int *argc, char *argv[], #if defined(HAVE_LOGGER) logger_init(); #elif defined(HAVE_FILE_LOGGER) - global_t *global = global_get_ptr(); - global->log_file = fopen("sdmc:/retroarch/retroarch-log.txt", "w"); + retro_main_log_file_init("sdmc:/retroarch/retroarch-log.txt"); #endif #endif @@ -108,7 +107,6 @@ static void frontend_ctr_deinit(void *data) u8 not_2DS; (void)data; #ifndef IS_SALAMANDER - global_t *global = global_get_ptr(); bool *verbose = retro_main_verbosity(); *verbose = true; @@ -197,7 +195,6 @@ static void frontend_ctr_init(void *data) { #ifndef IS_SALAMANDER (void)data; - global_t *global = global_get_ptr(); bool *verbose = retro_main_verbosity(); *verbose = true; diff --git a/frontend/drivers/platform_gx.c b/frontend/drivers/platform_gx.c index 46f2eca1d9..334a8d889b 100644 --- a/frontend/drivers/platform_gx.c +++ b/frontend/drivers/platform_gx.c @@ -149,9 +149,7 @@ int gx_logger_net(struct _reent *r, int fd, const char *ptr, size_t len) #elif defined(HAVE_FILE_LOGGER) int gx_logger_file(struct _reent *r, int fd, const char *ptr, size_t len) { - global_t *global = global_get_ptr(); - - fwrite(ptr, 1, len, global->log_file); + fwrite(ptr, 1, len, retro_main_log_file()); return len; } #endif @@ -169,8 +167,7 @@ static void frontend_gx_get_environment_settings(int *argc, char *argv[], #if defined(HAVE_LOGGER) logger_init(); #elif defined(HAVE_FILE_LOGGER) - global_t *global = global_get_ptr(); - global->log_file = fopen("/retroarch-log.txt", "w"); + retro_main_log_file_init("/retroarch-log.txt"); #endif #endif diff --git a/frontend/drivers/platform_ps3.c b/frontend/drivers/platform_ps3.c index dff32ea3a3..98f7e76a58 100644 --- a/frontend/drivers/platform_ps3.c +++ b/frontend/drivers/platform_ps3.c @@ -97,7 +97,6 @@ static void frontend_ps3_get_environment_settings(int *argc, char *argv[], void *args, void *params_data) { #ifndef IS_SALAMANDER - global_t *global = global_get_ptr(); bool *verbose = retro_main_verbosity(); bool original_verbose = *verbose; *verbose = true; @@ -108,7 +107,7 @@ static void frontend_ps3_get_environment_settings(int *argc, char *argv[], #if defined(HAVE_LOGGER) logger_init(); #elif defined(HAVE_FILE_LOGGER) - global->log_file = fopen("/retroarch-log.txt", "w"); + retro_main_log_file_init("/retroarch-log.txt"); #endif #endif @@ -361,7 +360,6 @@ static void frontend_ps3_exec(const char *path, bool should_load_game) { #ifndef IS_SALAMANDER char *fullpath = NULL; - global_t *global = global_get_ptr(); bool *verbose = retro_main_verbosity(); bool original_verbose = *verbose; @@ -411,7 +409,6 @@ static void frontend_ps3_exitspawn(char *core_path, size_t core_path_size) bool should_load_game = false; #ifndef IS_SALAMANDER - global_t *global = global_get_ptr(); bool *verbose = retro_main_verbosity(); bool original_verbose = *verbose; diff --git a/frontend/drivers/platform_psp.c b/frontend/drivers/platform_psp.c index b3732e97d3..5657c37d49 100644 --- a/frontend/drivers/platform_psp.c +++ b/frontend/drivers/platform_psp.c @@ -80,8 +80,7 @@ static void frontend_psp_get_environment_settings(int *argc, char *argv[], logger_init(); #elif defined(HAVE_FILE_LOGGER) #ifndef VITA - global_t *global = global_get_ptr(); - global->log_file = fopen("ms0:/retroarch-log.txt", "w"); + retro_main_log_file_init("ms0:/retroarch-log.txt"); #endif #endif #endif diff --git a/frontend/drivers/platform_xdk.cpp b/frontend/drivers/platform_xdk.cpp index 9b632a11f6..f1c68bfdc7 100644 --- a/frontend/drivers/platform_xdk.cpp +++ b/frontend/drivers/platform_xdk.cpp @@ -73,7 +73,6 @@ HRESULT xbox_io_mount(const char* szDrive, char* szDevice) static HRESULT xbox_io_mount(char *szDrive, char *szDevice) { #ifndef IS_SALAMANDER - global_t *global = global_get_ptr(); bool *verbose = retro_main_verbosity(); bool original_verbose = *verbose; *verbose = true; @@ -135,7 +134,6 @@ static void frontend_xdk_get_environment_settings(int *argc, char *argv[], (void)ret; #ifndef IS_SALAMANDER - global_t *global = global_get_ptr(); bool *verbose = retro_main_verbosity(); bool original_verbose = *verbose; @@ -146,7 +144,7 @@ static void frontend_xdk_get_environment_settings(int *argc, char *argv[], #if defined(HAVE_LOGGER) logger_init(); #elif defined(HAVE_FILE_LOGGER) - global->log_file = fopen("/retroarch-log.txt", "w"); + retro_main_log_file_init("/retroarch-log.txt"); #endif #endif @@ -312,7 +310,6 @@ static void frontend_xdk_exitspawn(char *s, size_t len) static void frontend_xdk_exec(const char *path, bool should_load_game) { #ifndef IS_SALAMANDER - global_t *global = global_get_ptr(); bool *verbose = retro_main_verbosity(); bool original_verbose = *verbose; *verbose = true; diff --git a/retroarch.c b/retroarch.c index 5929b1aed3..90609c28f0 100644 --- a/retroarch.c +++ b/retroarch.c @@ -890,7 +890,7 @@ static void parse_input(int argc, char *argv[]) #ifdef HAVE_FILE_LOGGER case RA_OPT_LOG_FILE: - global->log_file = fopen(optarg, "wb"); + retro_main_log_file_init(optarg); break; #endif @@ -1141,7 +1141,7 @@ int rarch_main_init(int argc, char *argv[]) return sjlj_ret; } global->inited.error = true; - global->log_file = stderr; + retro_main_log_file_init(NULL); parse_input(argc, argv); verbosity = retro_main_verbosity(); diff --git a/runloop.c b/runloop.c index d48123633a..9858d9a8e6 100644 --- a/runloop.c +++ b/runloop.c @@ -765,14 +765,6 @@ static void rarch_main_iterate_linefeed_overlay(driver_t *driver, } #endif -FILE *retro_main_log_file(void) -{ - global_t *global = global_get_ptr(); - if (!global) - return NULL; - return global->log_file; -} - #ifdef HAVE_MENU static bool rarch_main_cmd_get_state_menu_toggle_button_combo( driver_t *driver, settings_t *settings, diff --git a/runloop.h b/runloop.h index d89186f586..ab09f173d8 100644 --- a/runloop.h +++ b/runloop.h @@ -309,10 +309,6 @@ typedef struct global async_job_t *async_jobs; #endif - /* If this is non-NULL. RARCH_LOG and friends - * will write to this file. */ - FILE *log_file; - struct { bool main; @@ -354,8 +350,6 @@ void rarch_main_msg_queue_free(void); void rarch_main_msg_queue_init(void); -FILE *retro_main_log_file(void); - bool rarch_main_ctl(enum rarch_main_ctl_state state, void *data); #ifdef __cplusplus diff --git a/verbosity.c b/verbosity.c index 2b3a5fc49c..14c75db20b 100644 --- a/verbosity.c +++ b/verbosity.c @@ -17,7 +17,32 @@ static bool main_verbosity; +/* If this is non-NULL. RARCH_LOG and friends + * will write to this file. */ +static FILE *log_file; + bool *retro_main_verbosity(void) { return &main_verbosity; } + +FILE *retro_main_log_file(void) +{ + return log_file; +} + +void retro_main_log_file_init(const char *path) +{ + log_file = stderr; + if (path == NULL) + return; + + log_file = fopen(path, "wb"); +} + +void retro_main_log_file_deinit(void) +{ + if (log_file && log_file != stderr) + fclose(log_file); + log_file = NULL; +} diff --git a/verbosity.h b/verbosity.h index 0baf442dbf..804a4f8b54 100644 --- a/verbosity.h +++ b/verbosity.h @@ -46,14 +46,18 @@ extern "C" { bool *retro_main_verbosity(void); +FILE *retro_main_log_file(void); + +void retro_main_log_file_deinit(void); + +void retro_main_log_file_init(const char *path); + #if defined(HAVE_FILE_LOGGER) #ifdef __cplusplus extern "C" #endif -FILE *retro_main_log_file(void); - #define LOG_FILE (retro_main_log_file()) #else