From b2634ea5885b6f09697c4b0d13e8d9c93ca381ea Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Thu, 4 Aug 2022 14:18:11 +0200 Subject: [PATCH] * Create fill_pathname_join_special - and specify fill_pathname_join as deprecated. * Use fill_pathname_join_special in the vast majority of cases where we can ensure out_path is a new empty string * Get rid of some extension concatenation with strlcat where encountered * Some general cleanups with NULL termination of strings that get immediately passed to strlcpy/strlcpy-adjacent functions --- audio/audio_driver.c | 2 +- cheat_manager.c | 18 ++-- cheevos/cheevos_client.c | 7 +- command.c | 8 +- configuration.c | 46 ++++----- core_backup.c | 14 +-- core_info.c | 15 +-- core_updater_list.c | 8 +- disk_index_file.c | 2 +- file_path_special.c | 90 ++++++++--------- frontend/drivers/platform_darwin.m | 10 +- frontend/drivers/platform_dos.c | 2 +- frontend/drivers/platform_emscripten.c | 10 +- frontend/drivers/platform_qnx.c | 29 +++--- frontend/drivers/platform_switch.c | 16 +++ frontend/drivers/platform_unix.c | 16 ++- frontend/frontend_salamander.c | 7 +- gfx/drivers_font_renderer/bitmapfont_10x10.c | 5 +- gfx/drivers_font_renderer/bitmapfont_6x10.c | 11 +-- gfx/gfx_display.c | 3 +- gfx/gfx_thumbnail_path.c | 8 +- gfx/gfx_widgets.c | 22 ++--- gfx/video_shader_parse.c | 8 +- .../gfx_widget_load_content_animation.c | 6 +- input/input_driver.c | 3 +- libretro-common/file/archive_file.c | 2 +- libretro-common/file/file_path.c | 35 ++++++- libretro-common/include/file/file_path.h | 33 ++++++- libretro-common/lists/dir_list.c | 2 +- libretro-common/samples/streams/rzip/rzip.c | 4 +- libretro-common/vfs/vfs_implementation.c | 2 +- manual_content_scan.c | 2 +- menu/cbs/menu_cbs_deferred_push.c | 6 +- menu/cbs/menu_cbs_ok.c | 98 +++++++++---------- menu/cbs/menu_cbs_scan.c | 4 +- menu/drivers/materialui.c | 19 ++-- menu/drivers/ozone.c | 46 +++++---- menu/drivers/rgui.c | 4 +- menu/drivers/xmb.c | 13 ++- menu/menu_contentless_cores.c | 13 ++- menu/menu_displaylist.c | 16 ++- menu/menu_driver.c | 8 +- menu/menu_explore.c | 4 +- menu/menu_screensaver.c | 4 +- network/discord.c | 2 +- network/drivers_wifi/connmanctl.c | 12 +-- record/record_driver.c | 8 +- retroarch.c | 14 +-- runloop.c | 4 +- runtime_file.c | 6 +- tasks/task_autodetect.c | 3 +- tasks/task_content.c | 2 +- tasks/task_content_disc.c | 4 +- tasks/task_core_updater.c | 4 +- tasks/task_database.c | 4 +- tasks/task_database_cue.c | 18 ++-- tasks/task_decompress.c | 6 +- tasks/task_pl_thumbnail_download.c | 6 +- tasks/task_screenshot.c | 4 +- ui/drivers/qt/qt_playlist.cpp | 7 +- verbosity.c | 5 +- 61 files changed, 424 insertions(+), 366 deletions(-) diff --git a/audio/audio_driver.c b/audio/audio_driver.c index 7b8ff872d4..f4a0d205cd 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -1356,7 +1356,7 @@ void audio_driver_load_system_sounds(void) sounds_path[0] = basename_noext[0] ='\0'; - fill_pathname_join( + fill_pathname_join_special( sounds_fallback_path, dir_assets, "sounds", diff --git a/cheat_manager.c b/cheat_manager.c index 34943abad2..d0d69e2524 100644 --- a/cheat_manager.c +++ b/cheat_manager.c @@ -164,8 +164,6 @@ bool cheat_manager_save( (char*)"cheat%u_repeat_add_to_address" }; - cheats_file[0] = '\0'; - if (!cheat_st->cheats || cheat_st->size == 0) return false; @@ -173,9 +171,13 @@ bool cheat_manager_save( strlcpy(cheats_file, path, sizeof(cheats_file)); else { - fill_pathname_join(cheats_file, + size_t len = fill_pathname_join_special(cheats_file, cheat_database, path, sizeof(cheats_file)); - strlcat(cheats_file, ".cht", sizeof(cheats_file)); + cheats_file[len ] = '.'; + cheats_file[len+1] = 'c'; + cheats_file[len+2] = 'h'; + cheats_file[len+3] = 't'; + cheats_file[len+4] = '\0'; } if (!overwrite) @@ -710,8 +712,6 @@ static bool cheat_manager_get_game_specific_filename( const char *core_name = NULL; const char *game_name = NULL; - s1[0] = '\0'; - if (!core_get_system_info(&system_info)) return false; @@ -723,9 +723,7 @@ static bool cheat_manager_get_game_specific_filename( string_is_empty(game_name)) return false; - s[0] = '\0'; - - fill_pathname_join(s1, + fill_pathname_join_special(s1, path_cheat_database, core_name, sizeof(s1)); @@ -736,7 +734,7 @@ static bool cheat_manager_get_game_specific_filename( path_mkdir(s1); } - fill_pathname_join(s, s1, game_name, len); + fill_pathname_join_special(s, s1, game_name, len); return true; } diff --git a/cheevos/cheevos_client.c b/cheevos/cheevos_client.c index 36e93e1345..d84f93c025 100644 --- a/cheevos/cheevos_client.c +++ b/cheevos/cheevos_client.c @@ -1445,9 +1445,10 @@ static void rcheevos_async_write_badge(retro_task_t* task) rcheevos_fetch_badge_data* badge_data = (rcheevos_fetch_badge_data*)task->user_data; - fill_pathname_join(badge_fullpath, badge_data->state->badge_directory, - badge_data->state->requested_badges[badge_data->request_index], - sizeof(badge_fullpath)); + fill_pathname_join_special(badge_fullpath, + badge_data->state->badge_directory, + badge_data->state->requested_badges[badge_data->request_index], + sizeof(badge_fullpath)); if (!filestream_write_file(badge_fullpath, badge_data->data, badge_data->data_len)) { diff --git a/command.c b/command.c index ab0dbd22ed..286dfbb60a 100644 --- a/command.c +++ b/command.c @@ -1437,7 +1437,7 @@ bool command_set_shader(command_t *cmd, const char *arg) { char abs_arg[PATH_MAX_LENGTH]; const char *ref_path = settings->paths.directory_video_shader; - fill_pathname_join(abs_arg, ref_path, arg, sizeof(abs_arg)); + fill_pathname_join_special(abs_arg, ref_path, arg, sizeof(abs_arg)); return apply_shader(settings, type, abs_arg, true); } } @@ -1476,8 +1476,6 @@ bool command_event_save_core_config( } core_path = path_get(RARCH_PATH_CORE); - config_name[0] = '\0'; - config_path[0] = '\0'; /* Infer file name based on libretro core. */ if (path_is_valid(core_path)) @@ -1488,7 +1486,7 @@ bool command_event_save_core_config( fill_pathname_base(config_name, core_path, sizeof(config_name)); path_remove_extension(config_name); - fill_pathname_join(config_path, config_dir, config_name, + fill_pathname_join_special(config_path, config_dir, config_name, sizeof(config_path)); /* In case of collision, find an alternative name. */ @@ -1513,7 +1511,7 @@ bool command_event_save_core_config( RARCH_WARN("[Config]: %s\n", msg_hash_to_str(MSG_CANNOT_INFER_NEW_CONFIG_PATH)); fill_dated_filename(config_name, ".cfg", sizeof(config_name)); - fill_pathname_join(config_path, config_dir, config_name, + fill_pathname_join_special(config_path, config_dir, config_name, sizeof(config_path)); } diff --git a/configuration.c b/configuration.c index 2245ba120e..c06b390caf 100644 --- a/configuration.c +++ b/configuration.c @@ -2863,12 +2863,10 @@ void config_set_defaults(void *data) sizeof(settings->paths.directory_overlay)); #ifdef RARCH_MOBILE if (string_is_empty(settings->paths.path_overlay)) - { - fill_pathname_join(settings->paths.path_overlay, + fill_pathname_join_special(settings->paths.path_overlay, settings->paths.directory_overlay, FILE_PATH_DEFAULT_OVERLAY, sizeof(settings->paths.path_overlay)); - } #endif } #endif @@ -2890,7 +2888,7 @@ void config_set_defaults(void *data) #if TARGET_OS_IPHONE { char config_file_path[PATH_MAX_LENGTH]; - fill_pathname_join(config_file_path, + fill_pathname_join_special(config_file_path, settings->paths.directory_menu_config, FILE_PATH_MAIN_CONFIG, sizeof(config_file_path)); @@ -3052,7 +3050,7 @@ static config_file_t *open_default_config_file(void) application_data[0] = '\0'; #endif - conf_path[0] = app_path[0] = '\0'; + app_path[0] = '\0'; #if defined(_WIN32) && !defined(_XBOX) #if defined(__WINRT__) || defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP @@ -3071,7 +3069,7 @@ static config_file_t *open_default_config_file(void) if (fill_pathname_application_data(application_data, sizeof(application_data))) { - fill_pathname_join(conf_path, application_data, + fill_pathname_join_special(conf_path, application_data, FILE_PATH_MAIN_CONFIG, sizeof(conf_path)); conf = config_file_new_from_path_to_string(conf_path); } @@ -3114,7 +3112,7 @@ static config_file_t *open_default_config_file(void) path_mkdir(application_data); - fill_pathname_join(conf_path, application_data, + fill_pathname_join_special(conf_path, application_data, FILE_PATH_MAIN_CONFIG, sizeof(conf_path)); conf = config_file_new_from_path_to_string(conf_path); @@ -3146,7 +3144,7 @@ static config_file_t *open_default_config_file(void) if (has_application_data) { - fill_pathname_join(conf_path, application_data, + fill_pathname_join_special(conf_path, application_data, FILE_PATH_MAIN_CONFIG, sizeof(conf_path)); RARCH_LOG("[Config]: Looking for config in: \"%s\".\n", conf_path); conf = config_file_new_from_path_to_string(conf_path); @@ -3155,7 +3153,7 @@ static config_file_t *open_default_config_file(void) /* Fallback to $HOME/.retroarch.cfg. */ if (!conf && getenv("HOME")) { - fill_pathname_join(conf_path, getenv("HOME"), + fill_pathname_join_special(conf_path, getenv("HOME"), "." FILE_PATH_MAIN_CONFIG, sizeof(conf_path)); RARCH_LOG("[Config]: Looking for config in: \"%s\".\n", conf_path); conf = config_file_new_from_path_to_string(conf_path); @@ -3167,7 +3165,7 @@ static config_file_t *open_default_config_file(void) char basedir[PATH_MAX_LENGTH]; /* Try to create a new config file. */ fill_pathname_basedir(basedir, application_data, sizeof(basedir)); - fill_pathname_join(conf_path, application_data, + fill_pathname_join_special(conf_path, application_data, FILE_PATH_MAIN_CONFIG, sizeof(conf_path)); dir_created = path_mkdir(basedir); @@ -3178,7 +3176,7 @@ static config_file_t *open_default_config_file(void) bool saved = false; /* Build a retroarch.cfg path from the * global config directory (/etc). */ - fill_pathname_join(skeleton_conf, GLOBAL_CONFIG_DIR, + fill_pathname_join_special(skeleton_conf, GLOBAL_CONFIG_DIR, FILE_PATH_MAIN_CONFIG, sizeof(skeleton_conf)); if ((conf = config_file_new_from_path_to_string(skeleton_conf))) RARCH_WARN("[Config]: Using skeleton config \"%s\" as base for a new config file.\n", skeleton_conf); @@ -3532,7 +3530,7 @@ static bool config_load_file(global_t *global, FILE_PATH_CONTENT_FAVORITES, sizeof(settings->paths.path_content_favorites)); else - fill_pathname_join( + fill_pathname_join_special( settings->paths.path_content_favorites, settings->paths.directory_content_favorites, FILE_PATH_CONTENT_FAVORITES, @@ -3548,7 +3546,7 @@ static bool config_load_file(global_t *global, FILE_PATH_CONTENT_HISTORY, sizeof(settings->paths.path_content_history)); else - fill_pathname_join( + fill_pathname_join_special( settings->paths.path_content_history, settings->paths.directory_content_history, FILE_PATH_CONTENT_HISTORY, @@ -3564,7 +3562,7 @@ static bool config_load_file(global_t *global, FILE_PATH_CONTENT_IMAGE_HISTORY, sizeof(settings->paths.path_content_image_history)); else - fill_pathname_join( + fill_pathname_join_special( settings->paths.path_content_image_history, settings->paths.directory_content_image_history, FILE_PATH_CONTENT_IMAGE_HISTORY, @@ -3580,7 +3578,7 @@ static bool config_load_file(global_t *global, FILE_PATH_CONTENT_MUSIC_HISTORY, sizeof(settings->paths.path_content_music_history)); else - fill_pathname_join( + fill_pathname_join_special( settings->paths.path_content_music_history, settings->paths.directory_content_music_history, FILE_PATH_CONTENT_MUSIC_HISTORY, @@ -3596,7 +3594,7 @@ static bool config_load_file(global_t *global, FILE_PATH_CONTENT_VIDEO_HISTORY, sizeof(settings->paths.path_content_video_history)); else - fill_pathname_join( + fill_pathname_join_special( settings->paths.path_content_video_history, settings->paths.directory_content_video_history, FILE_PATH_CONTENT_VIDEO_HISTORY, @@ -4430,6 +4428,7 @@ bool config_save_autoconf_profile(const "~", "#", "%", "&", "*", "{", "}", "\\", ":", "[", "]", "?", "/", "|", "\'", "\"", NULL }; + size_t len; unsigned i; char buf[PATH_MAX_LENGTH]; char autoconf_file[PATH_MAX_LENGTH]; @@ -4479,15 +4478,19 @@ bool config_save_autoconf_profile(const } /* Generate autoconfig file path */ - fill_pathname_join(buf, autoconf_dir, joypad_driver, sizeof(buf)); + fill_pathname_join_special(buf, autoconf_dir, joypad_driver, sizeof(buf)); if (path_is_directory(buf)) - fill_pathname_join(autoconf_file, buf, + len = fill_pathname_join_special(autoconf_file, buf, sanitised_name, sizeof(autoconf_file)); else - fill_pathname_join(autoconf_file, autoconf_dir, + len = fill_pathname_join_special(autoconf_file, autoconf_dir, sanitised_name, sizeof(autoconf_file)); - strlcat(autoconf_file, ".cfg", sizeof(autoconf_file)); + autoconf_file[len ] = '.'; + autoconf_file[len+1] = 'c'; + autoconf_file[len+2] = 'f'; + autoconf_file[len+3] = 'g'; + autoconf_file[len+4] = '\0'; /* Open config file */ if ( !(conf = config_file_new_from_path_to_string(autoconf_file)) @@ -4807,7 +4810,6 @@ bool config_save_overrides(enum override_type type, void *data) const char *game_name = NULL; bool has_content = !string_is_empty(rarch_path_basename); - config_directory[0] = '\0'; core_path[0] = '\0'; game_path[0] = '\0'; content_path[0] = '\0'; @@ -4828,7 +4830,7 @@ bool config_save_overrides(enum override_type type, void *data) sizeof(config_directory), APPLICATION_SPECIAL_DIRECTORY_CONFIG); - fill_pathname_join(override_directory, + fill_pathname_join_special(override_directory, config_directory, core_name, sizeof(override_directory)); diff --git a/core_backup.c b/core_backup.c index e660292414..4bf7180aa5 100644 --- a/core_backup.c +++ b/core_backup.c @@ -84,11 +84,13 @@ static bool core_backup_get_backup_dir( /* Get core backup directory * > If no assets directory is defined, use * core directory as a base */ - fill_pathname_join(tmp, string_is_empty(dir_core_assets) ? - dir_libretro : dir_core_assets, + fill_pathname_join_special(tmp, + string_is_empty(dir_core_assets) + ? dir_libretro + : dir_core_assets, "core_backups", sizeof(tmp)); - fill_pathname_join(backup_dir, tmp, + fill_pathname_join_special(backup_dir, tmp, core_file_id, len); if (string_is_empty(backup_dir)) @@ -163,7 +165,7 @@ bool core_backup_get_backup_path( FILE_PATH_CORE_BACKUP_EXTENSION); /* Build final path */ - fill_pathname_join(backup_path, backup_dir, + fill_pathname_join_special(backup_path, backup_dir, backup_filename, len); return true; @@ -379,7 +381,7 @@ enum core_backup_type core_backup_get_core_path( break; /* All good - build core path */ - fill_pathname_join(core_path, dir_libretro, + fill_pathname_join_special(core_path, dir_libretro, core_filename, len); backup_type = CORE_BACKUP_TYPE_ARCHIVE; @@ -387,7 +389,7 @@ enum core_backup_type core_backup_get_core_path( break; case CORE_BACKUP_TYPE_LIB: /* This is a plain dynamic library file */ - fill_pathname_join(core_path, dir_libretro, + fill_pathname_join_special(core_path, dir_libretro, backup_filename, len); backup_type = CORE_BACKUP_TYPE_LIB; break; diff --git a/core_info.c b/core_info.c index 966618f9d6..bc3bd5402a 100644 --- a/core_info.c +++ b/core_info.c @@ -709,7 +709,7 @@ static core_info_cache_list_t *core_info_cache_read(const char *info_dir) strlcpy(file_path, FILE_PATH_CORE_INFO_CACHE_REFRESH, sizeof(file_path)); else - fill_pathname_join(file_path, + fill_pathname_join_special(file_path, info_dir, FILE_PATH_CORE_INFO_CACHE_REFRESH, sizeof(file_path)); @@ -720,7 +720,8 @@ static core_info_cache_list_t *core_info_cache_read(const char *info_dir) if (string_is_empty(info_dir)) strlcpy(file_path, FILE_PATH_CORE_INFO_CACHE, sizeof(file_path)); else - fill_pathname_join(file_path, info_dir, FILE_PATH_CORE_INFO_CACHE, + fill_pathname_join_special(file_path, info_dir, + FILE_PATH_CORE_INFO_CACHE, sizeof(file_path)); #if defined(HAVE_ZLIB) @@ -828,7 +829,8 @@ static bool core_info_cache_write(core_info_cache_list_t *list, const char *info if (string_is_empty(info_dir)) strlcpy(file_path, FILE_PATH_CORE_INFO_CACHE, sizeof(file_path)); else - fill_pathname_join(file_path, info_dir, FILE_PATH_CORE_INFO_CACHE, + fill_pathname_join_special(file_path, info_dir, + FILE_PATH_CORE_INFO_CACHE, sizeof(file_path)); #if defined(CORE_INFO_CACHE_COMPRESS) @@ -1180,7 +1182,7 @@ static bool core_info_cache_write(core_info_cache_list_t *list, const char *info strlcpy(file_path, FILE_PATH_CORE_INFO_CACHE_REFRESH, sizeof(file_path)); else - fill_pathname_join(file_path, + fill_pathname_join_special(file_path, info_dir, FILE_PATH_CORE_INFO_CACHE_REFRESH, sizeof(file_path)); @@ -1230,7 +1232,7 @@ bool core_info_cache_force_refresh(const char *path_info) strlcpy(file_path, FILE_PATH_CORE_INFO_CACHE_REFRESH, sizeof(file_path)); else - fill_pathname_join(file_path, + fill_pathname_join_special(file_path, path_info, FILE_PATH_CORE_INFO_CACHE_REFRESH, sizeof(file_path)); @@ -1656,7 +1658,8 @@ static config_file_t *core_info_get_config_file( "%s" ".info", core_file_id); else { - size_t len = fill_pathname_join(info_path, info_dir, core_file_id, + size_t len = fill_pathname_join_special(info_path, info_dir, + core_file_id, sizeof(info_path)); info_path[len] = '.'; info_path[len+1] = 'i'; diff --git a/core_updater_list.c b/core_updater_list.c index 54438aea78..4793592d5b 100644 --- a/core_updater_list.c +++ b/core_updater_list.c @@ -430,14 +430,14 @@ static bool core_updater_list_set_paths( * > Leave blank if this is not a buildbot core */ if (list_type == CORE_UPDATER_LIST_TYPE_BUILDBOT) { - fill_pathname_join( + fill_pathname_join_special( remote_core_path, network_buildbot_url, filename_str, sizeof(remote_core_path)); /* > Apply proper URL encoding (messy...) */ - tmp_url = strdup(remote_core_path); + tmp_url = strdup(remote_core_path); remote_core_path[0] = '\0'; net_http_urlencode_full( remote_core_path, tmp_url, sizeof(remote_core_path)); @@ -453,7 +453,7 @@ static bool core_updater_list_set_paths( entry->remote_core_path = strdup(remote_core_path); - fill_pathname_join( + fill_pathname_join_special( local_core_path, path_dir_libretro, filename_str, @@ -473,7 +473,7 @@ static bool core_updater_list_set_paths( entry->local_core_path = strdup(local_core_path); - fill_pathname_join( + fill_pathname_join_special( local_info_path, path_libretro_info, filename_str, diff --git a/disk_index_file.c b/disk_index_file.c index b6018196eb..d71d288e12 100644 --- a/disk_index_file.c +++ b/disk_index_file.c @@ -267,7 +267,7 @@ bool disk_index_file_init( } /* > Generate final path */ - fill_pathname_join( + fill_pathname_join_special( disk_index_file_path, disk_index_file_dir, content_name, sizeof(disk_index_file_path)); strlcat( diff --git a/file_path_special.c b/file_path_special.c index af95f11e97..4cd72daf8f 100644 --- a/file_path_special.c +++ b/file_path_special.c @@ -171,9 +171,9 @@ void fill_pathname_application_special(char *s, char s8[PATH_MAX_LENGTH]; settings_t *settings = config_get_ptr(); const char *dir_assets = settings->paths.directory_assets; - fill_pathname_join(s8, dir_assets, "xmb", sizeof(s8)); - fill_pathname_join(s1, s8, xmb_theme_ident(), sizeof(s1)); - fill_pathname_join(s, s1, "png", len); + fill_pathname_join_special(s8, dir_assets, "xmb", sizeof(s8)); + fill_pathname_join_special(s1, s8, xmb_theme_ident(), sizeof(s1)); + fill_pathname_join_special(s, s1, "png", len); } #endif break; @@ -191,10 +191,10 @@ void fill_pathname_application_special(char *s, char s8[PATH_MAX_LENGTH]; char s3[PATH_MAX_LENGTH]; const char *dir_assets = settings->paths.directory_assets; - fill_pathname_join(s8, dir_assets, "xmb", sizeof(s8)); - fill_pathname_join(s1, s8, xmb_theme_ident(), sizeof(s1)); - fill_pathname_join(s3, s1, "png", sizeof(s3)); - fill_pathname_join(s, s3, FILE_PATH_BACKGROUND_IMAGE, len); + fill_pathname_join_special(s8, dir_assets, "xmb", sizeof(s8)); + fill_pathname_join_special(s1, s8, xmb_theme_ident(), sizeof(s1)); + fill_pathname_join_special(s3, s1, "png", sizeof(s3)); + fill_pathname_join_special(s, s3, FILE_PATH_BACKGROUND_IMAGE, len); } } #endif @@ -211,9 +211,9 @@ void fill_pathname_application_special(char *s, { char s8[PATH_MAX_LENGTH]; char s4[PATH_MAX_LENGTH]; - fill_pathname_join(s8, dir_assets, "xmb", sizeof(s8)); - fill_pathname_join(s4, s8, xmb_theme_ident(), sizeof(s4)); - fill_pathname_join(s, s4, "sounds", len); + fill_pathname_join_special(s8, dir_assets, "xmb", sizeof(s8)); + fill_pathname_join_special(s4, s8, xmb_theme_ident(), sizeof(s4)); + fill_pathname_join_special(s, s4, "sounds", len); } else #endif @@ -221,8 +221,8 @@ void fill_pathname_application_special(char *s, if (string_is_equal(menu_ident, "glui")) { char s4[PATH_MAX_LENGTH]; - fill_pathname_join(s4, dir_assets, "glui", sizeof(s4)); - fill_pathname_join(s, s4, "sounds", len); + fill_pathname_join_special(s4, dir_assets, "glui", sizeof(s4)); + fill_pathname_join_special(s, s4, "sounds", len); } else #endif @@ -230,14 +230,14 @@ void fill_pathname_application_special(char *s, if (string_is_equal(menu_ident, "ozone")) { char s4[PATH_MAX_LENGTH]; - fill_pathname_join(s4, dir_assets, "ozone", + fill_pathname_join_special(s4, dir_assets, "ozone", sizeof(s4)); - fill_pathname_join(s, s4, "sounds", len); + fill_pathname_join_special(s, s4, "sounds", len); } else #endif { - fill_pathname_join( + fill_pathname_join_special( s, dir_assets, "sounds", len); } #endif @@ -256,9 +256,9 @@ void fill_pathname_application_special(char *s, char s1[PATH_MAX_LENGTH]; char s8[PATH_MAX_LENGTH]; const char *dir_assets = settings->paths.directory_assets; - fill_pathname_join(s8, dir_assets, "xmb", sizeof(s8)); - fill_pathname_join(s1, s8, xmb_theme_ident(), sizeof(s1)); - fill_pathname_join(s, s1, "png", len); + fill_pathname_join_special(s8, dir_assets, "xmb", sizeof(s8)); + fill_pathname_join_special(s1, s8, xmb_theme_ident(), sizeof(s1)); + fill_pathname_join_special(s, s1, "png", len); } else #endif @@ -271,14 +271,14 @@ void fill_pathname_application_special(char *s, #if defined(WIIU) || defined(VITA) /* Smaller 46x46 icons look better on low-DPI devices */ - fill_pathname_join(s5, dir_assets, "ozone", sizeof(s5)); - fill_pathname_join(s6, "png", "icons", sizeof(s6)); + fill_pathname_join_special(s5, dir_assets, "ozone", sizeof(s5)); + fill_pathname_join_special(s6, "png", "icons", sizeof(s6)); #else /* Otherwise, use large 256x256 icons */ - fill_pathname_join(s5, dir_assets, "xmb", sizeof(s5)); - fill_pathname_join(s6, "monochrome", "png", sizeof(s6)); + fill_pathname_join_special(s5, dir_assets, "xmb", sizeof(s5)); + fill_pathname_join_special(s6, "monochrome", "png", sizeof(s6)); #endif - fill_pathname_join(s, s5, s6, len); + fill_pathname_join_special(s, s5, s6, len); } else if (len) s[0] = '\0'; @@ -296,14 +296,14 @@ void fill_pathname_application_special(char *s, #if defined(WIIU) || defined(VITA) /* Smaller 46x46 icons look better on low-DPI devices */ - fill_pathname_join(s5, dir_assets, "ozone", sizeof(s5)); - fill_pathname_join(s6, "png", "icons", sizeof(s6)); + fill_pathname_join_special(s5, dir_assets, "ozone", sizeof(s5)); + fill_pathname_join_special(s6, "png", "icons", sizeof(s6)); #else /* Otherwise, use large 256x256 icons */ - fill_pathname_join(s5, dir_assets, "xmb", sizeof(s5)); - fill_pathname_join(s6, "monochrome", "png", sizeof(s6)); + fill_pathname_join_special(s5, dir_assets, "xmb", sizeof(s5)); + fill_pathname_join_special(s6, "monochrome", "png", sizeof(s6)); #endif - fill_pathname_join(s, s5, s6, len); + fill_pathname_join_special(s, s5, s6, len); } #endif break; @@ -314,8 +314,8 @@ void fill_pathname_application_special(char *s, char s7[PATH_MAX_LENGTH]; settings_t *settings = config_get_ptr(); const char *dir_assets = settings->paths.directory_assets; - fill_pathname_join(s7, dir_assets, "rgui", sizeof(s7)); - fill_pathname_join(s, s7, "font", len); + fill_pathname_join_special(s7, dir_assets, "rgui", sizeof(s7)); + fill_pathname_join_special(s, s7, "font", len); } #endif break; @@ -326,8 +326,8 @@ void fill_pathname_application_special(char *s, char s8[PATH_MAX_LENGTH]; settings_t *settings = config_get_ptr(); const char *dir_assets = settings->paths.directory_assets; - fill_pathname_join(s8, dir_assets, "xmb", sizeof(s8)); - fill_pathname_join(s, s8, xmb_theme_ident(), len); + fill_pathname_join_special(s8, dir_assets, "xmb", sizeof(s8)); + fill_pathname_join_special(s, s8, xmb_theme_ident(), len); } #endif break; @@ -347,29 +347,29 @@ void fill_pathname_application_special(char *s, { case RETRO_LANGUAGE_ARABIC: case RETRO_LANGUAGE_PERSIAN: - fill_pathname_join(s9, + fill_pathname_join_special(s9, settings->paths.directory_assets, "pkg", sizeof(s9)); - fill_pathname_join(s, s9, "fallback-font.ttf", len); + fill_pathname_join_special(s, s9, "fallback-font.ttf", len); break; case RETRO_LANGUAGE_CHINESE_SIMPLIFIED: case RETRO_LANGUAGE_CHINESE_TRADITIONAL: - fill_pathname_join(s9, + fill_pathname_join_special(s9, settings->paths.directory_assets, "pkg", sizeof(s9)); - fill_pathname_join(s, s9, "chinese-fallback-font.ttf", len); + fill_pathname_join_special(s, s9, "chinese-fallback-font.ttf", len); break; case RETRO_LANGUAGE_KOREAN: - fill_pathname_join(s9, + fill_pathname_join_special(s9, settings->paths.directory_assets, "pkg", sizeof(s9)); - fill_pathname_join(s, s9, "korean-fallback-font.ttf", len); + fill_pathname_join_special(s, s9, "korean-fallback-font.ttf", len); break; default: { char s8[PATH_MAX_LENGTH]; settings_t *settings = config_get_ptr(); const char *dir_assets = settings->paths.directory_assets; - fill_pathname_join(s8, dir_assets, "xmb", sizeof(s8)); - fill_pathname_join(s9, s8, xmb_theme_ident(), sizeof(s9)); - fill_pathname_join(s, s9, FILE_PATH_TTF_FONT, len); + fill_pathname_join_special(s8, dir_assets, "xmb", sizeof(s8)); + fill_pathname_join_special(s9, s8, xmb_theme_ident(), sizeof(s9)); + fill_pathname_join_special(s, s9, FILE_PATH_TTF_FONT, len); } break; } @@ -382,8 +382,8 @@ void fill_pathname_application_special(char *s, char s10[PATH_MAX_LENGTH]; settings_t *settings = config_get_ptr(); const char *dir_thumbnails = settings->paths.directory_thumbnails; - fill_pathname_join(s10, dir_thumbnails, "discord", sizeof(s10)); - fill_pathname_join(s, s10, "avatars", len); + fill_pathname_join_special(s10, dir_thumbnails, "discord", sizeof(s10)); + fill_pathname_join_special(s, s10, "avatars", len); } break; @@ -392,8 +392,8 @@ void fill_pathname_application_special(char *s, char s12[PATH_MAX_LENGTH]; settings_t *settings = config_get_ptr(); const char *dir_thumbnails = settings->paths.directory_thumbnails; - fill_pathname_join(s12, dir_thumbnails, "cheevos", len); - fill_pathname_join(s, s12, "badges", len); + fill_pathname_join_special(s12, dir_thumbnails, "cheevos", len); + fill_pathname_join_special(s, s12, "badges", len); } break; diff --git a/frontend/drivers/platform_darwin.m b/frontend/drivers/platform_darwin.m index 8df58aec6a..4150ce226e 100644 --- a/frontend/drivers/platform_darwin.m +++ b/frontend/drivers/platform_darwin.m @@ -326,6 +326,7 @@ static void frontend_darwin_get_os(char *s, size_t len, int *major, int *minor) static void frontend_darwin_get_env(int *argc, char *argv[], void *args, void *params_data) { + char assets_zip_path[PATH_MAX_LENGTH]; CFURLRef bundle_url; CFStringRef bundle_path; CFURLRef resource_url; @@ -339,7 +340,7 @@ static void frontend_darwin_get_env(int *argc, char *argv[], char temp_dir[PATH_MAX_LENGTH] = {0}; char bundle_path_buf[PATH_MAX_LENGTH] = {0}; char resource_path_buf[PATH_MAX_LENGTH] = {0}; - char full_resource_path_buf[PATH_MAX_LENGTH] = {0}; + char full_resource_path_buf[PATH_MAX_LENGTH]; char home_dir_buf[PATH_MAX_LENGTH] = {0}; CFBundleRef bundle = CFBundleGetMainBundle(); @@ -359,7 +360,7 @@ static void frontend_darwin_get_env(int *argc, char *argv[], CFStringGetCString(resource_path, resource_path_buf, sizeof(resource_path_buf), kCFStringEncodingUTF8); CFRelease(resource_path); - fill_pathname_join(full_resource_path_buf, bundle_path_buf, resource_path_buf, sizeof(full_resource_path_buf)); + fill_pathname_join_special(full_resource_path_buf, bundle_path_buf, resource_path_buf, sizeof(full_resource_path_buf)); CFSearchPathForDirectoriesInDomains( home_dir_buf, sizeof(home_dir_buf)); @@ -454,7 +455,6 @@ static void frontend_darwin_get_env(int *argc, char *argv[], #endif - char assets_zip_path[PATH_MAX_LENGTH]; #if TARGET_OS_IOS { int major, minor; @@ -465,9 +465,9 @@ static void frontend_darwin_get_env(int *argc, char *argv[], #endif #if TARGET_OS_IOS - fill_pathname_join(assets_zip_path, bundle_path_buf, "assets.zip", sizeof(assets_zip_path)); + fill_pathname_join_special(assets_zip_path, bundle_path_buf, "assets.zip", sizeof(assets_zip_path)); #else - fill_pathname_join(assets_zip_path, full_resource_path_buf, "assets.zip", sizeof(assets_zip_path)); + fill_pathname_join_special(assets_zip_path, full_resource_path_buf, "assets.zip", sizeof(assets_zip_path)); #endif if (path_is_valid(assets_zip_path)) diff --git a/frontend/drivers/platform_dos.c b/frontend/drivers/platform_dos.c index 7db1fd37c0..5dd2097129 100644 --- a/frontend/drivers/platform_dos.c +++ b/frontend/drivers/platform_dos.c @@ -54,7 +54,7 @@ static void frontend_dos_get_env_settings(int *argc, char *argv[], void *data, void *params_data) { char *slash; - char base_path[PATH_MAX] = {0}; + char base_path[PATH_MAX]; retro_main_log_file_init("retrodos.txt", false); diff --git a/frontend/drivers/platform_emscripten.c b/frontend/drivers/platform_emscripten.c index eb87b3b578..6fdc3f303b 100644 --- a/frontend/drivers/platform_emscripten.c +++ b/frontend/drivers/platform_emscripten.c @@ -73,12 +73,14 @@ void cmd_take_screenshot(void) static void frontend_emscripten_get_env(int *argc, char *argv[], void *args, void *params_data) { - char base_path[PATH_MAX] = {0}; - char user_path[PATH_MAX] = {0}; + char base_path[PATH_MAX]; + char user_path[PATH_MAX]; const char *home = getenv("HOME"); if (home) { + base_path[0] = '\0'; + user_path[0] = '\0'; snprintf(base_path, sizeof(base_path), "%s/retroarch", home); snprintf(user_path, sizeof(user_path), @@ -86,8 +88,8 @@ static void frontend_emscripten_get_env(int *argc, char *argv[], } else { - snprintf(base_path, sizeof(base_path), "retroarch"); - snprintf(user_path, sizeof(user_path), "retroarch/userdata"); + strlcpy(base_path, "retroarch", sizeof(base_path)); + strlcpy(user_path, "retroarch/userdata", sizeof(user_path)); } fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE], base_path, diff --git a/frontend/drivers/platform_qnx.c b/frontend/drivers/platform_qnx.c index aced5f53dc..5c6a4bcb02 100644 --- a/frontend/drivers/platform_qnx.c +++ b/frontend/drivers/platform_qnx.c @@ -56,17 +56,21 @@ static void frontend_qnx_get_env_settings(int *argc, char *argv[], void *data, void *params_data) { unsigned i; - char data_assets_path[PATH_MAX] = {0}; - char assets_path[PATH_MAX] = {0}; - char data_path[PATH_MAX] = {0}; - char user_path[PATH_MAX] = {0}; - char tmp_path[PATH_MAX] = {0}; + char assets_path[PATH_MAX]; + char data_path[PATH_MAX]; + char user_path[PATH_MAX]; + char tmp_path[PATH_MAX]; + char data_assets_path[PATH_MAX]; char workdir[PATH_MAX] = {0}; getcwd(workdir, sizeof(workdir)); if(!string_is_empty(workdir)) { + assets_path[0] = '\0'; + data_path[0] = '\0'; + user_path[0] = '\0'; + tmp_path[0] = '\0'; snprintf(assets_path, sizeof(data_path), "%s/app/native/assets", workdir); snprintf(data_path, sizeof(data_path), @@ -78,10 +82,10 @@ static void frontend_qnx_get_env_settings(int *argc, char *argv[], } else { - snprintf(assets_path, sizeof(data_path), "app/native/assets"); - snprintf(data_path, sizeof(data_path), "data"); - snprintf(user_path, sizeof(user_path), "shared/misc/retroarch"); - snprintf(tmp_path, sizeof(user_path), "tmp"); + strlcpy(assets_path, "app/native/assets", sizeof(assets_path)); + strlcpy(data_path, "data", sizeof(data_path)); + strlcpy(user_path, "shared/misc/retroarch", sizeof(user_path)); + strlcpy(tmp_path, "tmp", sizeof(user_path)); } /* app data */ @@ -143,9 +147,8 @@ static void frontend_qnx_get_env_settings(int *argc, char *argv[], FILE_PATH_MAIN_CONFIG, sizeof(g_defaults.path_config)); /* bundle copy */ - snprintf(data_assets_path, - sizeof(data_assets_path), - "%s/%s", data_path, "assets"); + fill_pathname_join_special(data_assets_path, + data_path, "assets", sizeof(data_assets_path)); if (!filestream_exists(data_assets_path)) { @@ -162,7 +165,7 @@ static void frontend_qnx_get_env_settings(int *argc, char *argv[], } /* set GLUI as default menu */ - snprintf(g_defaults.settings_menu, sizeof(g_defaults.settings_menu), "glui"); + strlcpy(g_defaults.settings_menu, "glui", sizeof(g_defaults.settings_menu)); #ifndef IS_SALAMANDER dir_check_defaults("custom.ini"); diff --git a/frontend/drivers/platform_switch.c b/frontend/drivers/platform_switch.c index 0d7482a6ec..5484ae8406 100644 --- a/frontend/drivers/platform_switch.c +++ b/frontend/drivers/platform_switch.c @@ -1,3 +1,19 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + #include #include #include diff --git a/frontend/drivers/platform_unix.c b/frontend/drivers/platform_unix.c index b7a6011719..e5f3f50cb0 100644 --- a/frontend/drivers/platform_unix.c +++ b/frontend/drivers/platform_unix.c @@ -161,9 +161,9 @@ int system_property_get(const char *command, const char *args, char *value) { FILE *pipe; + char cmd[NAME_MAX_LENGTH]; int length = 0; char buffer[PATH_MAX_LENGTH] = {0}; - char cmd[NAME_MAX_LENGTH] = {0}; char *curpos = NULL; size_t buf_pos = strlcpy(cmd, command, sizeof(cmd)); @@ -622,13 +622,13 @@ static bool device_is_android_tv() bool test_permissions(const char *path) { + char buf[PATH_MAX_LENGTH]; bool ret = false; - char buf[PATH_MAX_LENGTH] = {0}; __android_log_print(ANDROID_LOG_INFO, "RetroArch", "Testing permissions for %s\n",path); - fill_pathname_join(buf, path, ".retroarch", sizeof(buf)); + fill_pathname_join_special(buf, path, ".retroarch", sizeof(buf)); ret = path_mkdir(buf); __android_log_print(ANDROID_LOG_INFO, @@ -2156,7 +2156,7 @@ static int frontend_unix_parse_drive_list(void *data, bool load_content) if (storage_permissions == INTERNAL_STORAGE_WRITABLE) { char user_data_path[PATH_MAX_LENGTH]; - fill_pathname_join(user_data_path, + fill_pathname_join_special(user_data_path, internal_storage_path, "RetroArch", sizeof(user_data_path)); @@ -2390,9 +2390,7 @@ static uint64_t frontend_unix_get_total_mem(void) line[0] = '\0'; /* Open /proc/meminfo */ - meminfo_file = fopen(PROC_MEMINFO_PATH, "r"); - - if (!meminfo_file) + if (!(meminfo_file = fopen(PROC_MEMINFO_PATH, "r"))) return 0; /* Parse lines @@ -2438,9 +2436,7 @@ static uint64_t frontend_unix_get_free_mem(void) line[0] = '\0'; /* Open /proc/meminfo */ - meminfo_file = fopen(PROC_MEMINFO_PATH, "r"); - - if (!meminfo_file) + if (!(meminfo_file = fopen(PROC_MEMINFO_PATH, "r"))) return 0; /* Parse lines diff --git a/frontend/frontend_salamander.c b/frontend/frontend_salamander.c index 94d0e28b59..d348de87db 100644 --- a/frontend/frontend_salamander.c +++ b/frontend/frontend_salamander.c @@ -125,7 +125,6 @@ static void salamander_init(char *s, size_t len) char config_path[PATH_MAX_LENGTH]; char config_dir[PATH_MAX_LENGTH]; - config_path[0] = '\0'; config_dir[0] = '\0'; /* Get salamander config file path */ @@ -135,7 +134,7 @@ static void salamander_init(char *s, size_t len) FILE_PATH_SALAMANDER_CONFIG, sizeof(config_path)); else - strcpy_literal(config_path, FILE_PATH_SALAMANDER_CONFIG); + strlcpy(config_path, FILE_PATH_SALAMANDER_CONFIG, sizeof(config_path)); /* Ensure that config directory exists */ fill_pathname_parent_dir(config_dir, config_path, sizeof(config_dir)); @@ -144,9 +143,7 @@ static void salamander_init(char *s, size_t len) path_mkdir(config_dir); /* Attempt to open config file */ - config = config_file_new_from_path_to_string(config_path); - - if (config) + if ((config = config_file_new_from_path_to_string(config_path))) { char libretro_path[PATH_MAX_LENGTH]; diff --git a/gfx/drivers_font_renderer/bitmapfont_10x10.c b/gfx/drivers_font_renderer/bitmapfont_10x10.c index d8d9a140c8..183c6e2cd3 100644 --- a/gfx/drivers_font_renderer/bitmapfont_10x10.c +++ b/gfx/drivers_font_renderer/bitmapfont_10x10.c @@ -80,9 +80,6 @@ bitmapfont_lut_t *bitmapfont_10x10_load(unsigned language) size_t symbol_index; size_t i, j; - font_dir[0] = '\0'; - font_path[0] = '\0'; - /* Get font file associated with * specified language */ switch (language) @@ -131,7 +128,7 @@ bitmapfont_lut_t *bitmapfont_10x10_load(unsigned language) /* Get font path */ fill_pathname_application_special(font_dir, sizeof(font_dir), APPLICATION_SPECIAL_DIRECTORY_ASSETS_RGUI_FONT); - fill_pathname_join(font_path, font_dir, font_file, + fill_pathname_join_special(font_path, font_dir, font_file, sizeof(font_path)); /* Attempt to read bitmap file */ diff --git a/gfx/drivers_font_renderer/bitmapfont_6x10.c b/gfx/drivers_font_renderer/bitmapfont_6x10.c index 86e2696ea3..237f2e183d 100644 --- a/gfx/drivers_font_renderer/bitmapfont_6x10.c +++ b/gfx/drivers_font_renderer/bitmapfont_6x10.c @@ -67,9 +67,6 @@ bitmapfont_lut_t *bitmapfont_6x10_load(unsigned language) size_t symbol_index; size_t i, j; - font_dir[0] = '\0'; - font_path[0] = '\0'; - /* Get font file associated with * specified language */ switch (language) @@ -131,7 +128,7 @@ bitmapfont_lut_t *bitmapfont_6x10_load(unsigned language) /* Get font path */ fill_pathname_application_special(font_dir, sizeof(font_dir), APPLICATION_SPECIAL_DIRECTORY_ASSETS_RGUI_FONT); - fill_pathname_join(font_path, font_dir, font_file, + fill_pathname_join_special(font_path, font_dir, font_file, sizeof(font_path)); /* Attempt to read bitmap file */ @@ -153,8 +150,7 @@ bitmapfont_lut_t *bitmapfont_6x10_load(unsigned language) num_glyphs = (glyph_max - glyph_min) + 1; /* Initialise font struct */ - font = (bitmapfont_lut_t*)calloc(1, sizeof(bitmapfont_lut_t)); - if (!font) + if (!(font = (bitmapfont_lut_t*)calloc(1, sizeof(bitmapfont_lut_t)))) goto error; font->glyph_min = glyph_min; @@ -163,8 +159,7 @@ bitmapfont_lut_t *bitmapfont_6x10_load(unsigned language) /* Note: Need to use a calloc() here, otherwise * we'll get undefined behaviour when calling * bitmapfont_free_lut() if the following loop fails */ - font->lut = (bool**)calloc(1, num_glyphs * sizeof(bool*)); - if (!font->lut) + if (!(font->lut = (bool**)calloc(1, num_glyphs * sizeof(bool*)))) goto error; /* Loop over all possible characters */ diff --git a/gfx/gfx_display.c b/gfx/gfx_display.c index fbef83d9f7..ab79b1c600 100644 --- a/gfx/gfx_display.c +++ b/gfx/gfx_display.c @@ -1207,7 +1207,8 @@ bool gfx_display_reset_textures_list( if (string_is_empty(texture_path)) return false; - fill_pathname_join(texpath, iconpath, texture_path, sizeof(texpath)); + fill_pathname_join_special(texpath, + iconpath, texture_path, sizeof(texpath)); if (!image_texture_load(&ti, texpath)) return false; diff --git a/gfx/gfx_thumbnail_path.c b/gfx/gfx_thumbnail_path.c index 2226bc5c08..db4866cd44 100644 --- a/gfx/gfx_thumbnail_path.c +++ b/gfx/gfx_thumbnail_path.c @@ -405,7 +405,7 @@ bool gfx_thumbnail_set_content_image( path_data->content_img, sizeof(path_data->content_label)); /* Set file path */ - fill_pathname_join(path_data->content_path, + fill_pathname_join_special(path_data->content_path, img_dir, img_name, sizeof(path_data->content_path)); /* Set core name to "imageviewer" */ @@ -645,15 +645,15 @@ bool gfx_thumbnail_update_path( /* > Normal content: assemble path */ /* >> Base + system name */ - fill_pathname_join(thumbnail_path, dir_thumbnails, + fill_pathname_join_special(thumbnail_path, dir_thumbnails, system_name, PATH_MAX_LENGTH * sizeof(char)); /* >> Add type */ - fill_pathname_join(tmp_buf, thumbnail_path, type, sizeof(tmp_buf)); + fill_pathname_join_special(tmp_buf, thumbnail_path, type, sizeof(tmp_buf)); /* >> Add content image */ thumbnail_path[0] = '\0'; - fill_pathname_join(thumbnail_path, tmp_buf, + fill_pathname_join_special(thumbnail_path, tmp_buf, path_data->content_img, PATH_MAX_LENGTH * sizeof(char)); } diff --git a/gfx/gfx_widgets.c b/gfx/gfx_widgets.c index 5699b98511..17a6de0f3c 100644 --- a/gfx/gfx_widgets.c +++ b/gfx/gfx_widgets.c @@ -810,14 +810,14 @@ static void gfx_widgets_layout( { case RETRO_LANGUAGE_ARABIC: case RETRO_LANGUAGE_PERSIAN: - fill_pathname_join(font_file, p_dispwidget->assets_pkg_dir, "fallback-font.ttf", sizeof(font_file)); + fill_pathname_join_special(font_file, p_dispwidget->assets_pkg_dir, "fallback-font.ttf", sizeof(font_file)); break; case RETRO_LANGUAGE_CHINESE_SIMPLIFIED: case RETRO_LANGUAGE_CHINESE_TRADITIONAL: - fill_pathname_join(font_file, p_dispwidget->assets_pkg_dir, "chinese-fallback-font.ttf", sizeof(font_file)); + fill_pathname_join_special(font_file, p_dispwidget->assets_pkg_dir, "chinese-fallback-font.ttf", sizeof(font_file)); break; case RETRO_LANGUAGE_KOREAN: - fill_pathname_join(font_file, p_dispwidget->assets_pkg_dir, "korean-fallback-font.ttf", sizeof(font_file)); + fill_pathname_join_special(font_file, p_dispwidget->assets_pkg_dir, "korean-fallback-font.ttf", sizeof(font_file)); break; default: strlcpy(font_file, p_dispwidget->ozone_regular_font_path, sizeof(font_file)); @@ -2019,42 +2019,42 @@ bool gfx_widgets_init( p_dispwidget->current_msgs_lock = slock_new(); #endif - fill_pathname_join( + fill_pathname_join_special( p_dispwidget->gfx_widgets_path, dir_assets, "menu_widgets", sizeof(p_dispwidget->gfx_widgets_path) ); - fill_pathname_join( + fill_pathname_join_special( p_dispwidget->xmb_path, dir_assets, "xmb", sizeof(p_dispwidget->xmb_path) ); /* Base path */ - fill_pathname_join(p_dispwidget->ozone_path, + fill_pathname_join_special(p_dispwidget->ozone_path, dir_assets, "ozone", sizeof(p_dispwidget->ozone_path)); - fill_pathname_join(p_dispwidget->ozone_regular_font_path, + fill_pathname_join_special(p_dispwidget->ozone_regular_font_path, p_dispwidget->ozone_path, "regular.ttf", sizeof(p_dispwidget->ozone_regular_font_path)); - fill_pathname_join(p_dispwidget->ozone_bold_font_path, + fill_pathname_join_special(p_dispwidget->ozone_bold_font_path, p_dispwidget->ozone_path, "bold.ttf", sizeof(p_dispwidget->ozone_bold_font_path)); - fill_pathname_join( + fill_pathname_join_special( theme_path, p_dispwidget->xmb_path, "monochrome", sizeof(theme_path) ); - fill_pathname_join( + fill_pathname_join_special( p_dispwidget->monochrome_png_path, theme_path, "png", sizeof(p_dispwidget->monochrome_png_path) ); - fill_pathname_join(p_dispwidget->assets_pkg_dir, + fill_pathname_join_special(p_dispwidget->assets_pkg_dir, settings->paths.directory_assets, "pkg", sizeof(p_dispwidget->assets_pkg_dir)); diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 609799cd0c..032186d886 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -1776,7 +1776,7 @@ bool video_shader_write_preset(const char *path, if (!shader || string_is_empty(path)) return false; - fill_pathname_join(preset_dir, shader_dir, "presets", sizeof(preset_dir)); + fill_pathname_join_special(preset_dir, shader_dir, "presets", sizeof(preset_dir)); /* If we should still save a referenced preset do it now */ if (reference) @@ -2320,7 +2320,7 @@ void dir_check_shader( if (shader && !string_is_empty(shader->loaded_preset_path)) { char last_shader_path[PATH_MAX_LENGTH]; - fill_pathname_join(last_shader_path, + fill_pathname_join_special(last_shader_path, last_shader_preset_dir, last_shader_preset_file_name, sizeof(last_shader_path)); @@ -2398,7 +2398,7 @@ static bool retroarch_load_shader_preset_internal( if (string_is_empty(special_name)) break; - fill_pathname_join(s, shader_directory, special_name, len); + fill_pathname_join_special(s, shader_directory, special_name, len); strlcat(s, video_shader_get_preset_extension(types[i]), len); } @@ -2444,7 +2444,7 @@ bool load_shader_preset(settings_t *settings, const char *core_name, } if (!string_is_empty(video_shader_directory)) - fill_pathname_join(old_presets_directory, + fill_pathname_join_special(old_presets_directory, video_shader_directory, "presets", sizeof(old_presets_directory)); else old_presets_directory[0] = '\0'; diff --git a/gfx/widgets/gfx_widget_load_content_animation.c b/gfx/widgets/gfx_widget_load_content_animation.c index b3269d6a0f..a53c8298a3 100644 --- a/gfx/widgets/gfx_widget_load_content_animation.c +++ b/gfx/widgets/gfx_widget_load_content_animation.c @@ -453,7 +453,7 @@ bool gfx_widget_start_load_content_animation(void) state->icon_file[len+3] = 'g'; state->icon_file[len+4] = '\0'; - fill_pathname_join(icon_path, + fill_pathname_join_special(icon_path, state->icon_directory, state->icon_file, sizeof(icon_path)); @@ -487,7 +487,7 @@ bool gfx_widget_start_load_content_animation(void) state->icon_file[len+3] = 'g'; state->icon_file[len+4] = '\0'; - fill_pathname_join(icon_path, + fill_pathname_join_special(icon_path, state->icon_directory, state->icon_file, sizeof(icon_path)); @@ -500,7 +500,7 @@ bool gfx_widget_start_load_content_animation(void) if (!state->has_icon) { strlcpy(state->icon_file, "retroarch.png", sizeof(state->icon_file)); - fill_pathname_join(icon_path, + fill_pathname_join_special(icon_path, state->icon_directory, state->icon_file, sizeof(icon_path)); diff --git a/input/input_driver.c b/input/input_driver.c index 96cd3e82a4..24e668a3ab 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -2924,7 +2924,8 @@ void input_config_set_device_config_path(unsigned port, const char *path) input_driver_state_t *input_st = &input_driver_st; if (fill_pathname_parent_dir_name(parent_dir_name, path, sizeof(parent_dir_name))) - fill_pathname_join(input_st->input_device_info[port].config_path, + fill_pathname_join_special( + input_st->input_device_info[port].config_path, parent_dir_name, path_basename_nocompression(path), sizeof(input_st->input_device_info[port].config_path)); } diff --git a/libretro-common/file/archive_file.c b/libretro-common/file/archive_file.c index 0ece100aae..5a9c21a899 100644 --- a/libretro-common/file/archive_file.c +++ b/libretro-common/file/archive_file.c @@ -112,7 +112,7 @@ static int file_archive_extract_cb(const char *name, const char *valid_exts, } if (userdata->extraction_directory) - fill_pathname_join(new_path, userdata->extraction_directory, + fill_pathname_join_special(new_path, userdata->extraction_directory, path_basename(name), sizeof(new_path)); else fill_pathname_resolve_relative(new_path, userdata->archive_path, diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index fc45f10bdb..1742f7afa3 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -906,13 +906,44 @@ void fill_pathname_resolve_relative(char *out_path, * Joins a directory (@dir) and path (@path) together. * Makes sure not to get two consecutive slashes * between directory and path. + * + * Deprecated. Use fill_pathname_join_special() instead + * if you can ensure @dir and @out_path won't overlap. + * + * @return The length of @out_path (NOT @size) **/ size_t fill_pathname_join(char *out_path, const char *dir, const char *path, size_t size) { - size_t len = 0; if (out_path != dir) - len = strlcpy(out_path, dir, size); + strlcpy(out_path, dir, size); + if (*out_path) + fill_pathname_slash(out_path, size); + return strlcat(out_path, path, size); +} + +/** + * fill_pathname_join_special: + * @out_path : output path + * @dir : directory. Cannot be identical to @out_path + * @path : path + * @size : size of output path + * + * + * Specialized version of fill_pathname_join. + * Unlike fill_pathname_join(), + * @dir and @out_path CANNOT be identical. + * + * Joins a directory (@dir) and path (@path) together. + * Makes sure not to get two consecutive slashes + * between directory and path. + * + * @return The length of @out_path (NOT @size) + **/ +size_t fill_pathname_join_special(char *out_path, + const char *dir, const char *path, size_t size) +{ + size_t len = strlcpy(out_path, dir, size); if (*out_path) { diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index 8613e8c9ff..77ff1bda33 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -451,12 +451,43 @@ void fill_pathname_resolve_relative(char *out_path, const char *in_refpath, * * Hidden non-leaf function cost: * - calls strlcpy - * - calls find_last_slash() + * - calls fill_pathname_slash() * - calls strlcat + * + * Deprecated. Use fill_pathname_join_special() instead + * if you can ensure @dir != @out_path + * + * @return The length of @out_path (NOT @size) **/ size_t fill_pathname_join(char *out_path, const char *dir, const char *path, size_t size); +/** + * fill_pathname_join_special: + * @out_path : output path + * @dir : directory. Cannot be identical to @out_path + * @path : path + * @size : size of output path + * + * + * Specialized version of fill_pathname_join. + * Unlike fill_pathname_join(), + * @dir and @out_path CANNOT be identical. + * + * Joins a directory (@dir) and path (@path) together. + * Makes sure not to get two consecutive slashes + * between directory and path. + * + * Hidden non-leaf function cost: + * - calls strlcpy + * - calls find_last_slash() + * - calls strlcat + * + * @return The length of @out_path (NOT @size) + **/ +size_t fill_pathname_join_special(char *out_path, + const char *dir, const char *path, size_t size); + size_t fill_pathname_join_special_ext(char *out_path, const char *dir, const char *path, const char *last, const char *ext, diff --git a/libretro-common/lists/dir_list.c b/libretro-common/lists/dir_list.c index 61e4c95972..e5e8182954 100644 --- a/libretro-common/lists/dir_list.c +++ b/libretro-common/lists/dir_list.c @@ -137,7 +137,7 @@ static int dir_list_read(const char *dir, continue; } - fill_pathname_join(file_path, dir, name, sizeof(file_path)); + fill_pathname_join_special(file_path, dir, name, sizeof(file_path)); if (retro_dirent_is_dir(entry, NULL)) { diff --git a/libretro-common/samples/streams/rzip/rzip.c b/libretro-common/samples/streams/rzip/rzip.c index 66eb3a4b5c..0d6bdd5250 100644 --- a/libretro-common/samples/streams/rzip/rzip.c +++ b/libretro-common/samples/streams/rzip/rzip.c @@ -157,10 +157,8 @@ int main(int argc, char *argv[]) rand_str(tmp_str, sizeof(tmp_str) - 1); tmp_str[0] = '.'; - out_file_path[0] = '\0'; - if (!string_is_empty(in_file_dir)) - fill_pathname_join(out_file_path, in_file_dir, + fill_pathname_join_special(out_file_path, in_file_dir, tmp_str, sizeof(out_file_path)); else strlcpy(out_file_path, tmp_str, sizeof(out_file_path)); diff --git a/libretro-common/vfs/vfs_implementation.c b/libretro-common/vfs/vfs_implementation.c index 6895b1b7b8..14334a8bf6 100644 --- a/libretro-common/vfs/vfs_implementation.c +++ b/libretro-common/vfs/vfs_implementation.c @@ -1158,7 +1158,7 @@ bool retro_vfs_dirent_is_dir_impl(libretro_vfs_implementation_dir *rdir) return false; #endif /* dirent struct doesn't have d_type, do it the slow way ... */ - fill_pathname_join(path, rdir->orig_path, retro_vfs_dirent_get_name_impl(rdir), sizeof(path)); + fill_pathname_join_special(path, rdir->orig_path, retro_vfs_dirent_get_name_impl(rdir), sizeof(path)); if (stat(path, &buf) < 0) return false; return S_ISDIR(buf.st_mode); diff --git a/manual_content_scan.c b/manual_content_scan.c index a0da613110..c338f93143 100644 --- a/manual_content_scan.c +++ b/manual_content_scan.c @@ -1056,7 +1056,7 @@ bool manual_content_scan_get_task_config( if (string_is_empty(path_dir_playlist)) return false; - fill_pathname_join( + fill_pathname_join_special( task_config->playlist_file, path_dir_playlist, task_config->database_name, diff --git a/menu/cbs/menu_cbs_deferred_push.c b/menu/cbs/menu_cbs_deferred_push.c index 9e17a69ec1..1bf2d163ca 100644 --- a/menu/cbs/menu_cbs_deferred_push.c +++ b/menu/cbs/menu_cbs_deferred_push.c @@ -315,7 +315,7 @@ static int deferred_push_cursor_manager_list_deferred( settings = config_get_ptr(); - fill_pathname_join(rdb_path, + fill_pathname_join_special(rdb_path, settings->paths.path_content_database, rdb_entry->value, sizeof(rdb_path)); @@ -424,9 +424,9 @@ static int general_push(menu_displaylist_info_t *info, { char tmp_str[PATH_MAX_LENGTH]; char tmp_str2[PATH_MAX_LENGTH]; - fill_pathname_join(tmp_str, menu->scratch2_buf, + fill_pathname_join_special(tmp_str, menu->scratch2_buf, menu->scratch_buf, sizeof(tmp_str)); - fill_pathname_join(tmp_str2, menu->scratch2_buf, + fill_pathname_join_special(tmp_str2, menu->scratch2_buf, menu->scratch_buf, sizeof(tmp_str2)); if (!string_is_empty(info->path)) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index c3372f777f..ba3308c076 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -860,7 +860,7 @@ int generic_action_ok_displaylist_push(const char *path, content_path = menu->scratch_buf; } if (content_path) - fill_pathname_join(menu->detect_content_path, + fill_pathname_join_special(menu->detect_content_path, menu_path, content_path, sizeof(menu->detect_content_path)); @@ -879,7 +879,7 @@ int generic_action_ok_displaylist_push(const char *path, content_path = menu->scratch_buf; } if (content_path) - fill_pathname_join(menu->detect_content_path, + fill_pathname_join_special(menu->detect_content_path, menu_path, content_path, sizeof(menu->detect_content_path)); @@ -1109,7 +1109,7 @@ int generic_action_ok_displaylist_push(const char *path, if (!string_is_empty(core_name) && !string_is_empty(settings->paths.directory_input_remapping)) { - fill_pathname_join(tmp, + fill_pathname_join_special(tmp, settings->paths.directory_input_remapping, core_name, sizeof(tmp)); if (!path_is_directory(tmp)) tmp[0] = '\0'; @@ -1218,7 +1218,7 @@ int generic_action_ok_displaylist_push(const char *path, info_label = label; dl_type = DISPLAYLIST_FILE_BROWSER_SELECT_FILE; - fill_pathname_join(rgui_assets_dir, + fill_pathname_join_special(rgui_assets_dir, settings->paths.directory_assets, "rgui", sizeof(rgui_assets_dir)); @@ -1326,7 +1326,7 @@ int generic_action_ok_displaylist_push(const char *path, parent_dir[0] = '\0'; if (path && menu_path) - fill_pathname_join(tmp, + fill_pathname_join_special(tmp, menu_path, path, sizeof(tmp)); fill_pathname_parent_dir(parent_dir, @@ -1344,7 +1344,7 @@ int generic_action_ok_displaylist_push(const char *path, if (!string_is_empty(path)) { if (!string_is_empty(menu_path)) - fill_pathname_join( + fill_pathname_join_special( tmp, menu_path, path, sizeof(tmp)); else strlcpy(tmp, path, sizeof(tmp)); @@ -1360,7 +1360,7 @@ int generic_action_ok_displaylist_push(const char *path, { char lpl_basename[PATH_MAX_LENGTH]; filebrowser_clear_type(); - fill_pathname_join(tmp, + fill_pathname_join_special(tmp, settings->paths.path_content_database, path, sizeof(tmp)); @@ -1378,7 +1378,7 @@ int generic_action_ok_displaylist_push(const char *path, break; case ACTION_OK_DL_CURSOR_MANAGER_LIST: filebrowser_clear_type(); - fill_pathname_join(tmp, settings->paths.directory_cursor, + fill_pathname_join_special(tmp, settings->paths.directory_cursor, path, sizeof(tmp)); info.directory_ptr = idx; @@ -1700,7 +1700,7 @@ static bool menu_content_find_first_core(menu_content_ctx_defer_info_t *def_info size_t default_info_length = def_info->len; if (!string_is_empty(default_info_path)) - fill_pathname_join(def_info->s, + fill_pathname_join_special(def_info->s, default_info_dir, default_info_path, default_info_length); @@ -1796,11 +1796,11 @@ static int file_load_with_detect_core_wrapper( if (string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_ARCHIVE_OPEN_DETECT_CORE))) - fill_pathname_join(menu_path_new, + fill_pathname_join_special(menu_path_new, menu->scratch2_buf, menu->scratch_buf, sizeof(menu_path_new)); else if (string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_ARCHIVE_OPEN))) - fill_pathname_join(menu_path_new, + fill_pathname_join_special(menu_path_new, menu->scratch2_buf, menu->scratch_buf, sizeof(menu_path_new)); core_info_get_list(&list); @@ -1818,7 +1818,7 @@ static int file_load_with_detect_core_wrapper( if ( !is_carchive && !string_is_empty(path) && !string_is_empty(menu_path_new)) - fill_pathname_join(menu->detect_content_path, + fill_pathname_join_special(menu->detect_content_path, menu_path_new, path, sizeof(menu->detect_content_path)); @@ -1965,7 +1965,7 @@ static int generic_action_ok(const char *path, &menu_label, NULL, &enum_idx, NULL); if (!string_is_empty(path)) - fill_pathname_join(action_path, + fill_pathname_join_special(action_path, menu_path, path, sizeof(action_path)); else strlcpy(action_path, menu_path, sizeof(action_path)); @@ -2298,7 +2298,7 @@ static int action_ok_file_load(const char *path, if (!menu) return menu_cbs_exit(); - fill_pathname_join(menu_path_new, + fill_pathname_join_special(menu_path_new, menu->scratch2_buf, menu->scratch_buf, sizeof(menu_path_new)); switch (type) @@ -2308,7 +2308,7 @@ static int action_ok_file_load(const char *path, '#',sizeof(full_path_new)); break; default: - fill_pathname_join(full_path_new, menu_path_new, path, + fill_pathname_join_special(full_path_new, menu_path_new, path, sizeof(full_path_new)); break; } @@ -2342,7 +2342,7 @@ static int action_ok_file_load(const char *path, if (!menu) return menu_cbs_exit(); - fill_pathname_join(menu_path_new, + fill_pathname_join_special(menu_path_new, menu->scratch2_buf, menu->scratch_buf, sizeof(menu_path_new)); } @@ -2355,7 +2355,7 @@ static int action_ok_file_load(const char *path, '#',sizeof(full_path_new)); break; default: - fill_pathname_join(full_path_new, menu_path_new, path, + fill_pathname_join_special(full_path_new, menu_path_new, path, sizeof(full_path_new)); break; } @@ -2902,7 +2902,7 @@ static int action_ok_audio_add_to_mixer_and_collection(const char *path, if (!menu) return menu_cbs_exit(); - fill_pathname_join(combined_path, menu->scratch2_buf, + fill_pathname_join_special(combined_path, menu->scratch2_buf, menu->scratch_buf, sizeof(combined_path)); /* The push function reads our entry as const, @@ -2932,7 +2932,7 @@ static int action_ok_audio_add_to_mixer_and_collection_and_play(const char *path if (!menu) return menu_cbs_exit(); - fill_pathname_join(combined_path, menu->scratch2_buf, + fill_pathname_join_special(combined_path, menu->scratch2_buf, menu->scratch_buf, sizeof(combined_path)); /* the push function reads our entry as const, so these casts are safe */ @@ -3921,11 +3921,10 @@ static int action_ok_file_load_ffmpeg(const char *path, file_list_get_last(menu_stack, &menu_path, NULL, NULL, NULL); - new_path[0] = '\0'; - - if (!string_is_empty(menu_path)) - fill_pathname_join(new_path, menu_path, path, - sizeof(new_path)); + if (string_is_empty(menu_path)) + return -1; + fill_pathname_join_special(new_path, menu_path, path, + sizeof(new_path)); /* TODO/FIXME - should become runtime optional */ #ifdef HAVE_MPV @@ -3946,7 +3945,7 @@ static int action_ok_audio_run(const char *path, if (!menu) return menu_cbs_exit(); - fill_pathname_join(combined_path, menu->scratch2_buf, + fill_pathname_join_special(combined_path, menu->scratch2_buf, menu->scratch_buf, sizeof(combined_path)); /* TODO/FIXME - should become runtime optional */ @@ -4366,7 +4365,7 @@ static int action_ok_file_load_imageviewer(const char *path, fullpath[0] = '\0'; if (!string_is_empty(menu_path)) - fill_pathname_join(fullpath, menu_path, path, + fill_pathname_join_special(fullpath, menu_path, path, sizeof(fullpath)); return default_action_ok_load_content_with_core_from_menu(fullpath, CORE_TYPE_IMAGEVIEWER); @@ -4707,7 +4706,7 @@ static int generic_action_ok_network(const char *path, if (string_is_empty(network_buildbot_assets_url)) return menu_cbs_exit(); - fill_pathname_join(url_path, + fill_pathname_join_special(url_path, network_buildbot_assets_url, "cores/" FILE_PATH_INDEX_DIRS_URL, sizeof(url_path)); @@ -4717,7 +4716,7 @@ static int generic_action_ok_network(const char *path, suppress_msg = true; break; case MENU_ENUM_LABEL_CB_CORE_CONTENT_LIST: - fill_pathname_join(url_path, path, + fill_pathname_join_special(url_path, path, FILE_PATH_INDEX_URL, sizeof(url_path)); url_label = msg_hash_to_str(enum_idx); type_id2 = ACTION_OK_DL_CORE_CONTENT_LIST; @@ -4727,7 +4726,7 @@ static int generic_action_ok_network(const char *path, case MENU_ENUM_LABEL_CB_CORE_SYSTEM_FILES_LIST: if (string_is_empty(network_buildbot_assets_url)) return menu_cbs_exit(); - fill_pathname_join(url_path, + fill_pathname_join_special(url_path, network_buildbot_assets_url, "system/" FILE_PATH_INDEX_URL, sizeof(url_path)); @@ -4737,7 +4736,7 @@ static int generic_action_ok_network(const char *path, suppress_msg = true; break; case MENU_ENUM_LABEL_CB_THUMBNAILS_UPDATER_LIST: - fill_pathname_join(url_path, + fill_pathname_join_special(url_path, FILE_PATH_CORE_THUMBNAILPACKS_URL, FILE_PATH_INDEX_URL, sizeof(url_path)); url_label = msg_hash_to_str(enum_idx); @@ -4747,10 +4746,10 @@ static int generic_action_ok_network(const char *path, #ifdef HAVE_LAKKA case MENU_ENUM_LABEL_CB_LAKKA_LIST: /* TODO unhardcode this path */ - fill_pathname_join(url_path, + fill_pathname_join_special(url_path, FILE_PATH_LAKKA_URL, lakka_get_project(), sizeof(url_path)); - fill_pathname_join(url_path, url_path, + fill_pathname_join_special(url_path, url_path, FILE_PATH_INDEX_URL, sizeof(url_path)); url_label = msg_hash_to_str(enum_idx); @@ -4875,7 +4874,7 @@ void cb_generic_download(retro_task_t *task, break; } - fill_pathname_join(shaderdir, dir_video_shader, + fill_pathname_join_special(shaderdir, dir_video_shader, dirname, sizeof(shaderdir)); if (!path_is_directory(shaderdir) && !path_mkdir(shaderdir)) @@ -4900,7 +4899,7 @@ void cb_generic_download(retro_task_t *task, } if (!string_is_empty(dir_path)) - fill_pathname_join(output_path, dir_path, + fill_pathname_join_special(output_path, dir_path, transf->path, sizeof(output_path)); /* Make sure the directory exists @@ -4917,7 +4916,7 @@ void cb_generic_download(retro_task_t *task, } if (!string_is_empty(dir_path)) - fill_pathname_join(output_path, dir_path, + fill_pathname_join_special(output_path, dir_path, transf->path, sizeof(output_path)); #ifdef HAVE_COMPRESSION @@ -4995,7 +4994,7 @@ static int action_ok_download_generic(const char *path, s3[0] = '\0'; - fill_pathname_join(s, + fill_pathname_join_special(s, network_buildbot_assets_url, "frontend", sizeof(s)); @@ -5003,7 +5002,7 @@ static int action_ok_download_generic(const char *path, { case MENU_ENUM_LABEL_CB_DOWNLOAD_URL: suppress_msg = true; - fill_pathname_join(s, label, + fill_pathname_join_special(s, label, path, sizeof(s)); path = s; cb = cb_generic_dir_download; @@ -5019,14 +5018,14 @@ static int action_ok_download_generic(const char *path, } break; case MENU_ENUM_LABEL_CB_CORE_SYSTEM_FILES_DOWNLOAD: - fill_pathname_join(s, + fill_pathname_join_special(s, network_buildbot_assets_url, "system", sizeof(s)); break; case MENU_ENUM_LABEL_CB_LAKKA_DOWNLOAD: #ifdef HAVE_LAKKA /* TODO unhardcode this path*/ - fill_pathname_join(s, FILE_PATH_LAKKA_URL, + fill_pathname_join_special(s, FILE_PATH_LAKKA_URL, lakka_get_project(), sizeof(s)); #endif break; @@ -5065,7 +5064,7 @@ static int action_ok_download_generic(const char *path, break; } - fill_pathname_join(s2, s, path, sizeof(s2)); + fill_pathname_join_special(s2, s, path, sizeof(s2)); transf = (file_transfer_t*)calloc(1, sizeof(*transf)); transf->enum_idx = enum_idx; @@ -5184,7 +5183,7 @@ static int action_ok_sideload_core(const char *path, &menu_path, NULL, NULL, NULL, NULL); if (!string_is_empty(menu_path)) - fill_pathname_join( + fill_pathname_join_special( backup_path, menu_path, core_file, sizeof(backup_path)); else strlcpy(backup_path, core_file, sizeof(backup_path)); @@ -6954,7 +6953,7 @@ static int action_ok_load_archive(const char *path, menu_path = menu->scratch2_buf; content_path = menu->scratch_buf; - fill_pathname_join(menu->detect_content_path, + fill_pathname_join_special(menu->detect_content_path, menu_path, content_path, sizeof(menu->detect_content_path)); @@ -6997,7 +6996,8 @@ static int action_ok_load_archive_detect_core(const char *path, new_core_path, sizeof(new_core_path))) ret = -1; - fill_pathname_join(menu->detect_content_path, menu_path, content_path, + fill_pathname_join_special( + menu->detect_content_path, menu_path, content_path, sizeof(menu->detect_content_path)); switch (ret) @@ -7292,7 +7292,7 @@ static int action_ok_disk_image_append(const char *path, if (!string_is_empty(menu_path)) { if (!string_is_empty(path)) - fill_pathname_join(image_path, + fill_pathname_join_special(image_path, menu_path, path, sizeof(image_path)); else strlcpy(image_path, menu_path, sizeof(image_path)); @@ -7746,9 +7746,7 @@ static int action_ok_pl_content_thumbnails(const char *path, if (!string_is_empty(path_dir_playlist)) { char playlist_path[PATH_MAX_LENGTH]; - playlist_path[0] = '\0'; - - fill_pathname_join( + fill_pathname_join_special( playlist_path, path_dir_playlist, label, sizeof(playlist_path)); playlist_config_set_path(&playlist_config, playlist_path); @@ -7903,13 +7901,9 @@ static int action_ok_playlist_refresh(const char *path, if (!scan_record_valid) { char msg[PATH_MAX_LENGTH]; - msg[0] = '\0'; - if (string_is_empty(msg_subject)) msg_subject = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE); - - fill_pathname_join(msg, msg_prefix, msg_subject, sizeof(msg)); - + fill_pathname_join_special(msg, msg_prefix, msg_subject, sizeof(msg)); RARCH_ERR(log_text, msg_subject); runloop_msg_queue_push(msg, 1, 150, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); diff --git a/menu/cbs/menu_cbs_scan.c b/menu/cbs/menu_cbs_scan.c index 2fc1648f77..23c2cfb473 100644 --- a/menu/cbs/menu_cbs_scan.c +++ b/menu/cbs/menu_cbs_scan.c @@ -58,7 +58,7 @@ int action_scan_file(const char *path, menu_entries_get_last_stack(&menu_path, NULL, NULL, NULL, NULL); - fill_pathname_join(fullpath, menu_path, path, sizeof(fullpath)); + fill_pathname_join_special(fullpath, menu_path, path, sizeof(fullpath)); task_push_dbscan( directory_playlist, @@ -83,7 +83,7 @@ int action_scan_directory(const char *path, menu_entries_get_last_stack(&menu_path, NULL, NULL, NULL, NULL); if (path) - fill_pathname_join(fullpath, menu_path, path, sizeof(fullpath)); + fill_pathname_join_special(fullpath, menu_path, path, sizeof(fullpath)); else strlcpy(fullpath, menu_path, sizeof(fullpath)); diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 16c2fa2712..029db318e5 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -7743,33 +7743,32 @@ static void materialui_init_font( } { char s1[PATH_MAX_LENGTH]; - s1[0] = '\0'; switch (*msg_hash_get_uint(MSG_HASH_USER_LANGUAGE)) { case RETRO_LANGUAGE_ARABIC: case RETRO_LANGUAGE_PERSIAN: - fill_pathname_join(s1, + fill_pathname_join_special(s1, settings->paths.directory_assets, "pkg", sizeof(s1)); - fill_pathname_join(fontpath, s1, "fallback-font.ttf", + fill_pathname_join_special(fontpath, s1, "fallback-font.ttf", sizeof(fontpath)); break; case RETRO_LANGUAGE_CHINESE_SIMPLIFIED: case RETRO_LANGUAGE_CHINESE_TRADITIONAL: - fill_pathname_join(s1, + fill_pathname_join_special(s1, settings->paths.directory_assets, "pkg", sizeof(s1)); - fill_pathname_join(fontpath, s1, "chinese-fallback-font.ttf", + fill_pathname_join_special(fontpath, s1, "chinese-fallback-font.ttf", sizeof(fontpath)); break; case RETRO_LANGUAGE_KOREAN: - fill_pathname_join(s1, + fill_pathname_join_special(s1, settings->paths.directory_assets, "pkg", sizeof(s1)); - fill_pathname_join(fontpath, s1, "korean-fallback-font.ttf", + fill_pathname_join_special(fontpath, s1, "korean-fallback-font.ttf", sizeof(fontpath)); break; default: - fill_pathname_join(s1, dir_assets, "glui", sizeof(s1)); - fill_pathname_join(fontpath, s1, FILE_PATH_TTF_FONT, + fill_pathname_join_special(s1, dir_assets, "glui", sizeof(s1)); + fill_pathname_join_special(fontpath, s1, FILE_PATH_TTF_FONT, sizeof(fontpath)); break; } @@ -8084,7 +8083,7 @@ static void *materialui_init(void **userdata, bool video_is_threaded) fill_pathname_application_special(mui->sysicons_path, sizeof(mui->sysicons_path), APPLICATION_SPECIAL_DIRECTORY_ASSETS_OZONE_ICONS); - fill_pathname_join(mui->icons_path, dir_assets, "glui", + fill_pathname_join_special(mui->icons_path, dir_assets, "glui", sizeof(mui->icons_path)); p_anim->updatetime_cb = materialui_menu_animation_update_time; diff --git a/menu/drivers/ozone.c b/menu/drivers/ozone.c index cd69d938ee..6490ba5ec8 100644 --- a/menu/drivers/ozone.c +++ b/menu/drivers/ozone.c @@ -2581,7 +2581,7 @@ static bool ozone_reset_theme_textures(ozone_handle_t *ozone) if (!theme->name) continue; - fill_pathname_join( + fill_pathname_join_special( theme_path, ozone->png_path, theme->name, @@ -4478,7 +4478,7 @@ static void ozone_context_reset_horizontal_list(ozone_handle_t *ozone) fill_pathname_base(sysname, path, sizeof(sysname)); path_remove_extension(sysname); - len = fill_pathname_join(texturepath, ozone->icons_path, sysname, + len = fill_pathname_join_special(texturepath, ozone->icons_path, sysname, sizeof(texturepath)); texturepath[len] = '.'; texturepath[len+1] = 'p'; @@ -4489,7 +4489,7 @@ static void ozone_context_reset_horizontal_list(ozone_handle_t *ozone) /* If the playlist icon doesn't exist return default */ if (!path_is_valid(texturepath)) { - len = fill_pathname_join(texturepath, ozone->icons_path, "default", + len = fill_pathname_join_special(texturepath, ozone->icons_path, "default", sizeof(texturepath)); texturepath[len] = '.'; texturepath[len+1] = 'p'; @@ -4517,7 +4517,7 @@ static void ozone_context_reset_horizontal_list(ozone_handle_t *ozone) fill_pathname_join_delim(sysname, sysname, "content.png", '-', sizeof(sysname)); - fill_pathname_join(content_texturepath, ozone->icons_path, sysname, + fill_pathname_join_special(content_texturepath, ozone->icons_path, sysname, sizeof(content_texturepath)); /* If the content icon doesn't exist, return default-content */ @@ -7824,7 +7824,7 @@ static void *ozone_init(void **userdata, bool video_is_threaded) ozone->last_onscreen_category = 0; /* Assets path */ - fill_pathname_join( + fill_pathname_join_special( ozone->assets_path, directory_assets, "ozone", @@ -7832,7 +7832,7 @@ static void *ozone_init(void **userdata, bool video_is_threaded) ); /* PNG path */ - fill_pathname_join( + fill_pathname_join_special( ozone->png_path, ozone->assets_path, "png", @@ -7840,7 +7840,7 @@ static void *ozone_init(void **userdata, bool video_is_threaded) ); /* Sidebar path */ - fill_pathname_join( + fill_pathname_join_special( ozone->tab_path, ozone->png_path, "sidebar", @@ -7851,7 +7851,7 @@ static void *ozone_init(void **userdata, bool video_is_threaded) fill_pathname_application_special(ozone->icons_path, sizeof(ozone->icons_path), APPLICATION_SPECIAL_DIRECTORY_ASSETS_OZONE_ICONS); - fill_pathname_join(ozone->icons_path_default, ozone->icons_path, + fill_pathname_join_special(ozone->icons_path_default, ozone->icons_path, "default", sizeof(ozone->icons_path_default)); ozone_last_use_preferred_system_color_theme = settings->bools.menu_use_preferred_system_color_theme; @@ -8070,8 +8070,6 @@ static void ozone_set_layout( bool font_inited = false; float scale_factor = ozone->last_scale_factor; - s1[0] = '\0'; - /* Calculate dimensions */ ozone->dimensions.header_height = HEADER_HEIGHT * scale_factor; ozone->dimensions.footer_height = FOOTER_HEIGHT * scale_factor; @@ -8129,23 +8127,23 @@ static void ozone_set_layout( { case RETRO_LANGUAGE_ARABIC: case RETRO_LANGUAGE_PERSIAN: - fill_pathname_join(s1, + fill_pathname_join_special(s1, settings->paths.directory_assets, "pkg", sizeof(s1)); - fill_pathname_join(font_path, s1, "fallback-font.ttf", sizeof(font_path)); + fill_pathname_join_special(font_path, s1, "fallback-font.ttf", sizeof(font_path)); break; case RETRO_LANGUAGE_CHINESE_SIMPLIFIED: case RETRO_LANGUAGE_CHINESE_TRADITIONAL: - fill_pathname_join(s1, + fill_pathname_join_special(s1, settings->paths.directory_assets, "pkg", sizeof(s1)); - fill_pathname_join(font_path, s1, "chinese-fallback-font.ttf", sizeof(font_path)); + fill_pathname_join_special(font_path, s1, "chinese-fallback-font.ttf", sizeof(font_path)); break; case RETRO_LANGUAGE_KOREAN: - fill_pathname_join(s1, + fill_pathname_join_special(s1, settings->paths.directory_assets, "pkg", sizeof(s1)); - fill_pathname_join(font_path, s1, "korean-fallback-font.ttf", sizeof(font_path)); + fill_pathname_join_special(font_path, s1, "korean-fallback-font.ttf", sizeof(font_path)); break; default: - fill_pathname_join(font_path, ozone->assets_path, "bold.ttf", sizeof(font_path)); + fill_pathname_join_special(font_path, ozone->assets_path, "bold.ttf", sizeof(font_path)); } font_inited = ozone_init_font(&ozone->fonts.title, @@ -8156,23 +8154,23 @@ static void ozone_set_layout( { case RETRO_LANGUAGE_ARABIC: case RETRO_LANGUAGE_PERSIAN: - fill_pathname_join(s1, + fill_pathname_join_special(s1, settings->paths.directory_assets, "pkg", sizeof(s1)); - fill_pathname_join(font_path, s1, "fallback-font.ttf", sizeof(font_path)); + fill_pathname_join_special(font_path, s1, "fallback-font.ttf", sizeof(font_path)); break; case RETRO_LANGUAGE_CHINESE_SIMPLIFIED: case RETRO_LANGUAGE_CHINESE_TRADITIONAL: - fill_pathname_join(s1, + fill_pathname_join_special(s1, settings->paths.directory_assets, "pkg", sizeof(s1)); - fill_pathname_join(font_path, s1, "chinese-fallback-font.ttf", sizeof(font_path)); + fill_pathname_join_special(font_path, s1, "chinese-fallback-font.ttf", sizeof(font_path)); break; case RETRO_LANGUAGE_KOREAN: - fill_pathname_join(s1, + fill_pathname_join_special(s1, settings->paths.directory_assets, "pkg", sizeof(s1)); - fill_pathname_join(font_path, s1, "korean-fallback-font.ttf", sizeof(font_path)); + fill_pathname_join_special(font_path, s1, "korean-fallback-font.ttf", sizeof(font_path)); break; default: - fill_pathname_join(font_path, ozone->assets_path, "regular.ttf", sizeof(font_path)); + fill_pathname_join_special(font_path, ozone->assets_path, "regular.ttf", sizeof(font_path)); } font_inited = ozone_init_font(&ozone->fonts.footer, diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index af9a0a1b71..2971fdfd37 100644 --- a/menu/drivers/rgui.c +++ b/menu/drivers/rgui.c @@ -2901,7 +2901,7 @@ static void update_dynamic_theme_path(rgui_t *rgui, const char *theme_dir) if (rgui->is_playlist && !string_is_empty(rgui->menu_title)) { - size_t len = fill_pathname_join(rgui->theme_dynamic_path, theme_dir, + size_t len = fill_pathname_join_special(rgui->theme_dynamic_path, theme_dir, rgui->menu_title, sizeof(rgui->theme_dynamic_path)); rgui->theme_dynamic_path[len ] = '.'; rgui->theme_dynamic_path[len+1] = 'c'; @@ -2913,7 +2913,7 @@ static void update_dynamic_theme_path(rgui_t *rgui, const char *theme_dir) } if (!use_playlist_theme) - fill_pathname_join(rgui->theme_dynamic_path, theme_dir, + fill_pathname_join_special(rgui->theme_dynamic_path, theme_dir, "default.cfg", sizeof(rgui->theme_dynamic_path)); } diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 997c417d8e..341a87fcd0 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -1100,7 +1100,7 @@ static char* xmb_path_dynamic_wallpaper(xmb_handle_t *xmb) if (tmp) { - len = fill_pathname_join( + len = fill_pathname_join_special( path, dir_dynamic_wallpapers, tmp, @@ -2276,10 +2276,9 @@ static void xmb_context_reset_horizontal_list( RHMAP_FREE(xmb->playlist_db_node_map); - iconpath[0] = '\0'; fill_pathname_application_special(iconpath, sizeof(iconpath), APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS); - fill_pathname_join(icons_path_default, iconpath, + fill_pathname_join_special(icons_path_default, iconpath, "default", sizeof(icons_path_default)); for (i = 0; i < list_size; i++) @@ -2310,7 +2309,7 @@ static void xmb_context_reset_horizontal_list( fill_pathname_base(sysname, path, sizeof(sysname)); path_remove_extension(sysname); - len = fill_pathname_join(texturepath, iconpath, sysname, + len = fill_pathname_join_special(texturepath, iconpath, sysname, sizeof(texturepath)); texturepath[len ] = '.'; texturepath[len+1] = 'p'; @@ -2322,7 +2321,7 @@ static void xmb_context_reset_horizontal_list( if (!path_is_valid(texturepath)) { - len = fill_pathname_join(texturepath, iconpath, "default", + len = fill_pathname_join_special(texturepath, iconpath, "default", sizeof(texturepath)); texturepath[len ] = '.'; texturepath[len+1] = 'p'; @@ -2351,7 +2350,7 @@ static void xmb_context_reset_horizontal_list( fill_pathname_join_delim(sysname, sysname, FILE_PATH_CONTENT_BASENAME, '-', sizeof(sysname)); - fill_pathname_join(content_texturepath, iconpath, sysname, + fill_pathname_join_special(content_texturepath, iconpath, sysname, sizeof(content_texturepath)); /* If the content icon doesn't exist return default-content */ @@ -6797,7 +6796,7 @@ static void xmb_context_reset_background(xmb_handle_t *xmb, const char *iconpath } else if (!string_is_empty(iconpath)) { - fill_pathname_join(path, iconpath, + fill_pathname_join_special(path, iconpath, FILE_PATH_BACKGROUND_IMAGE, sizeof(path)); if (path_is_valid(path)) diff --git a/menu/menu_contentless_cores.c b/menu/menu_contentless_cores.c index 2dedf398d6..518e1cb11d 100644 --- a/menu/menu_contentless_cores.c +++ b/menu/menu_contentless_cores.c @@ -265,8 +265,6 @@ static void contentless_cores_load_icons(contentless_cores_state_t *state) char icon_path[PATH_MAX_LENGTH]; size_t i; - icon_directory[0] = '\0'; - if (!state) return; @@ -289,7 +287,7 @@ static void contentless_cores_load_icons(contentless_cores_state_t *state) return; /* Load fallback icon */ - fill_pathname_join(icon_path, icon_directory, + fill_pathname_join_special(icon_path, icon_directory, CONTENTLESS_CORE_ICON_DEFAULT, sizeof(icon_path)); if (path_is_valid(icon_path)) @@ -325,14 +323,19 @@ static void contentless_cores_load_icons(contentless_cores_state_t *state) core_info->databases_list && (core_info->databases_list->size > 0)) { + size_t len; const char *icon_name = core_info->databases_list->elems[0].data; struct texture_image ti = {0}; ti.supports_rgba = rgba_supported; - fill_pathname_join(icon_path, icon_directory, + fill_pathname_join_special(icon_path, icon_directory, icon_name, sizeof(icon_path)); - strlcat(icon_path, ".png", sizeof(icon_path)); + icon_path[len ] = '.'; + icon_path[len+1] = 'p'; + icon_path[len+2] = 'n'; + icon_path[len+3] = 'g'; + icon_path[len+4] = '\0'; if (!path_is_valid(icon_path)) continue; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 885cc2a1de..4bd48ee698 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -2451,7 +2451,7 @@ static int menu_displaylist_parse_database_entry(menu_handle_t *menu, strlcat(path_base, ".lpl", sizeof(path_base)); - fill_pathname_join(path_playlist, dir_playlist, path_base, + fill_pathname_join_special(path_playlist, dir_playlist, path_base, sizeof(path_playlist)); playlist_config_set_path(&playlist_config, path_playlist); @@ -3298,7 +3298,7 @@ static int menu_displaylist_parse_horizontal_list( char path_playlist[PATH_MAX_LENGTH]; const char *dir_playlist = settings->paths.directory_playlist; - fill_pathname_join(path_playlist, dir_playlist, item->path, + fill_pathname_join_special(path_playlist, dir_playlist, item->path, sizeof(path_playlist)); /* Horizontal lists are always 'collections' @@ -4312,7 +4312,7 @@ static unsigned menu_displaylist_parse_cores( char display_name[PATH_MAX_LENGTH]; display_name[0] = '\0'; - fill_pathname_join(core_path, dir, path, sizeof(core_path)); + fill_pathname_join_special(core_path, dir, path, sizeof(core_path)); if (core_info_list_get_display_name(list, core_path, display_name, sizeof(display_name))) @@ -4713,9 +4713,7 @@ static unsigned menu_displaylist_parse_content_information( { char db_path[PATH_MAX_LENGTH]; - db_path[0] = '\0'; - - fill_pathname_join(db_path, + fill_pathname_join_special(db_path, settings->paths.path_content_database, db_name, sizeof(db_path)); @@ -11509,7 +11507,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, char combined_path[PATH_MAX_LENGTH]; const char *ext = NULL; - fill_pathname_join(combined_path, menu->scratch2_buf, + fill_pathname_join_special(combined_path, menu->scratch2_buf, menu->scratch_buf, sizeof(combined_path)); ext = path_get_extension(combined_path); @@ -11934,7 +11932,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, const char * network_buildbot_assets_url = settings->paths.network_buildbot_assets_url; - fill_pathname_join(new_label, + fill_pathname_join_special(new_label, network_buildbot_assets_url, "cores", sizeof(new_label)); @@ -12140,7 +12138,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, char path_playlist[PATH_MAX_LENGTH]; playlist_t *playlist = NULL; const char *dir_playlist = settings->paths.directory_playlist; - fill_pathname_join( + fill_pathname_join_special( path_playlist, dir_playlist, info->path, diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 58bcec0b96..443968fbf8 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -3870,7 +3870,7 @@ bool menu_shader_manager_operate_auto_preset( /* We are only including this directory for compatibility purposes with * versions 1.8.7 and older. */ if (op != AUTO_SHADER_OP_SAVE && !string_is_empty(dir_video_shader)) - fill_pathname_join( + fill_pathname_join_special( old_presets_directory, dir_video_shader, "presets", @@ -3886,19 +3886,19 @@ bool menu_shader_manager_operate_auto_preset( strcpy_literal(file, "global"); break; case SHADER_PRESET_CORE: - fill_pathname_join(file, core_name, core_name, sizeof(file)); + fill_pathname_join_special(file, core_name, core_name, sizeof(file)); break; case SHADER_PRESET_PARENT: fill_pathname_parent_dir_name(tmp, rarch_path_basename, sizeof(tmp)); - fill_pathname_join(file, core_name, tmp, sizeof(file)); + fill_pathname_join_special(file, core_name, tmp, sizeof(file)); break; case SHADER_PRESET_GAME: { const char *game_name = path_basename(rarch_path_basename); if (string_is_empty(game_name)) return false; - fill_pathname_join(file, core_name, game_name, sizeof(file)); + fill_pathname_join_special(file, core_name, game_name, sizeof(file)); break; } default: diff --git a/menu/menu_explore.c b/menu/menu_explore.c index 310c04d378..613df2d187 100644 --- a/menu/menu_explore.c +++ b/menu/menu_explore.c @@ -483,7 +483,7 @@ explore_state_t *menu_explore_build_list(const char *directory_playlist, if (!fext || strcasecmp(fext, ".lpl")) continue; - fill_pathname_join(playlist_config.path, + fill_pathname_join_special(playlist_config.path, directory_playlist, fname, sizeof(playlist_config.path)); playlist_config.capacity = COLLECTION_SIZE; playlist = playlist_init(&playlist_config); @@ -536,7 +536,7 @@ explore_state_t *menu_explore_build_list(const char *directory_playlist, memcpy(newrdb.systemname, db_name, systemname_len); newrdb.systemname[systemname_len] = '\0'; - fill_pathname_join( + fill_pathname_join_special( tmp, directory_database, db_name, sizeof(tmp)); path_remove_extension(tmp); strlcat(tmp, ".rdb", sizeof(tmp)); diff --git a/menu/menu_screensaver.c b/menu/menu_screensaver.c index fa49d63aa8..2376726183 100644 --- a/menu/menu_screensaver.c +++ b/menu/menu_screensaver.c @@ -462,11 +462,11 @@ static bool menu_screensaver_update_state( char pkg_path[PATH_MAX_LENGTH]; /* Get font file path */ if (!string_is_empty(dir_assets)) - fill_pathname_join(pkg_path, dir_assets, MENU_SS_PKG_DIR, sizeof(pkg_path)); + fill_pathname_join_special(pkg_path, dir_assets, MENU_SS_PKG_DIR, sizeof(pkg_path)); else strlcpy(pkg_path, MENU_SS_PKG_DIR, sizeof(pkg_path)); - fill_pathname_join(font_file, pkg_path, MENU_SS_FONT_FILE, + fill_pathname_join_special(font_file, pkg_path, MENU_SS_FONT_FILE, sizeof(font_file)); /* Warn if font file is missing */ diff --git a/network/discord.c b/network/discord.c index 43c1561949..e881760157 100644 --- a/network/discord.c +++ b/network/discord.c @@ -107,7 +107,7 @@ static bool discord_download_avatar( fill_pathname_application_special(buf, sizeof(buf), APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_DISCORD_AVATARS); - fill_pathname_join(full_path, buf, avatar_id, sizeof(full_path)); + fill_pathname_join_special(full_path, buf, avatar_id, sizeof(full_path)); strlcpy(discord_st->user_avatar, avatar_id, sizeof(discord_st->user_avatar)); diff --git a/network/drivers_wifi/connmanctl.c b/network/drivers_wifi/connmanctl.c index de147d9876..f3b008f86e 100644 --- a/network/drivers_wifi/connmanctl.c +++ b/network/drivers_wifi/connmanctl.c @@ -321,10 +321,10 @@ static bool connmanctl_connect_ssid( void *data, const wifi_network_info_t *netinfo) { unsigned i; - bool success = false; - char settings_dir[PATH_MAX_LENGTH] = {0}; - char settings_path[PATH_MAX_LENGTH] = {0}; - char netid[160] = {0}; + char netid[160]; + char settings_dir[PATH_MAX_LENGTH]; + char settings_path[PATH_MAX_LENGTH]; + bool success = false; connman_t *connman = (connman_t*)data; settings_t *settings = config_get_ptr(); static struct string_list* list = NULL; @@ -333,12 +333,12 @@ static bool connmanctl_connect_ssid( connman->connmanctl_widgets_supported; #endif strlcpy(netid, netinfo->netid, sizeof(netid)); - fill_pathname_join(settings_dir, LAKKA_CONNMAN_DIR, + fill_pathname_join_special(settings_dir, LAKKA_CONNMAN_DIR, netid, sizeof(settings_dir)); path_mkdir(settings_dir); - fill_pathname_join(settings_path, settings_dir, "settings", + fill_pathname_join_special(settings_path, settings_dir, "settings", sizeof(settings_path)); if (!netinfo->saved_password) diff --git a/record/record_driver.c b/record/record_driver.c index 79c0f1e279..4f02b478b1 100644 --- a/record/record_driver.c +++ b/record/record_driver.c @@ -260,27 +260,27 @@ bool recording_init(void) { fill_str_dated_filename(buf, game_name, "mkv", sizeof(buf)); - fill_pathname_join(output, recording_st->output_dir, buf, sizeof(output)); + fill_pathname_join_special(output, recording_st->output_dir, buf, sizeof(output)); } else if (video_record_quality >= RECORD_CONFIG_TYPE_RECORDING_WEBM_FAST && video_record_quality < RECORD_CONFIG_TYPE_RECORDING_GIF) { fill_str_dated_filename(buf, game_name, "webm", sizeof(buf)); - fill_pathname_join(output, recording_st->output_dir, buf, sizeof(output)); + fill_pathname_join_special(output, recording_st->output_dir, buf, sizeof(output)); } else if (video_record_quality >= RECORD_CONFIG_TYPE_RECORDING_GIF && video_record_quality < RECORD_CONFIG_TYPE_RECORDING_APNG) { fill_str_dated_filename(buf, game_name, "gif", sizeof(buf)); - fill_pathname_join(output, recording_st->output_dir, buf, sizeof(output)); + fill_pathname_join_special(output, recording_st->output_dir, buf, sizeof(output)); } else { fill_str_dated_filename(buf, game_name, "png", sizeof(buf)); - fill_pathname_join(output, recording_st->output_dir, buf, sizeof(output)); + fill_pathname_join_special(output, recording_st->output_dir, buf, sizeof(output)); } } } diff --git a/retroarch.c b/retroarch.c index 8f8acbaa55..6e38c39778 100644 --- a/retroarch.c +++ b/retroarch.c @@ -745,7 +745,7 @@ void retroarch_path_set_redirect(settings_t *settings) { /* Append content directory name to save location */ if (sort_savefiles_by_content_enable) - fill_pathname_join( + fill_pathname_join_special( new_savefile_dir, old_savefile_dir, content_dir_name, @@ -753,7 +753,7 @@ void retroarch_path_set_redirect(settings_t *settings) /* Append library_name to the save location */ if (sort_savefiles_enable) - fill_pathname_join( + fill_pathname_join_special( new_savefile_dir, new_savefile_dir, system->library_name, @@ -778,7 +778,7 @@ void retroarch_path_set_redirect(settings_t *settings) { /* Append content directory name to savestate location */ if (sort_savestates_by_content_enable) - fill_pathname_join( + fill_pathname_join_special( new_savestate_dir, old_savestate_dir, content_dir_name, @@ -787,7 +787,7 @@ void retroarch_path_set_redirect(settings_t *settings) /* Append library_name to the savestate location */ if (sort_savestates_enable) { - fill_pathname_join( + fill_pathname_join_special( new_savestate_dir, new_savestate_dir, system->library_name, @@ -843,7 +843,7 @@ void retroarch_path_set_redirect(settings_t *settings) if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL) && !netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_SERVER, NULL)) { - fill_pathname_join(new_savefile_dir, new_savefile_dir, ".netplay", + fill_pathname_join_special(new_savefile_dir, new_savefile_dir, ".netplay", sizeof(new_savefile_dir)); if (!path_is_directory(new_savefile_dir) && @@ -4379,7 +4379,7 @@ static void retroarch_parse_input_libretro_path(const char *path) !string_is_equal(path_ext, core_ext)) goto end; - fill_pathname_join(tmp_path, settings->paths.directory_libretro, + fill_pathname_join_special(tmp_path, settings->paths.directory_libretro, path, sizeof(tmp_path)); if (string_is_empty(tmp_path)) @@ -4825,7 +4825,7 @@ static bool retroarch_parse_input_and_config( strlcpy(video_st->cli_shader_path, optarg, sizeof(video_st->cli_shader_path)); else - fill_pathname_join(video_st->cli_shader_path, + fill_pathname_join_special(video_st->cli_shader_path, settings->paths.directory_video_shader, optarg, sizeof(video_st->cli_shader_path)); #endif diff --git a/runloop.c b/runloop.c index 4491016b1e..7c1269f676 100644 --- a/runloop.c +++ b/runloop.c @@ -1080,7 +1080,7 @@ static bool validate_per_core_options(char *s, if (mkdir && !path_is_valid(s)) { char new_path[PATH_MAX_LENGTH]; - fill_pathname_join(new_path, + fill_pathname_join_special(new_path, config_directory, core_name, sizeof(new_path)); if (!path_is_directory(new_path)) path_mkdir(new_path); @@ -3935,7 +3935,7 @@ static char *copy_core_to_temp_file( if (!(tmpdir = get_tmpdir_alloc(dir_libretro))) return NULL; - fill_pathname_join(tmp_path, + fill_pathname_join_special(tmp_path, tmpdir, "retroarch_temp", sizeof(tmp_path)); diff --git a/runtime_file.c b/runtime_file.c index fef5d1a8b2..6da1828ccb 100644 --- a/runtime_file.c +++ b/runtime_file.c @@ -283,7 +283,7 @@ runtime_log_t *runtime_log_init( * If 'custom' runtime log path is undefined, * use default 'playlists/logs' directory... */ if (string_is_empty(dir_runtime_log)) - fill_pathname_join( + fill_pathname_join_special( tmp_buf, dir_playlist, "logs", @@ -295,7 +295,7 @@ runtime_log_t *runtime_log_init( return NULL; if (log_per_core) - fill_pathname_join( + fill_pathname_join_special( log_file_dir, tmp_buf, core_name, @@ -363,7 +363,7 @@ runtime_log_t *runtime_log_init( return NULL; /* Build final log file path */ - len = fill_pathname_join(log_file_path, log_file_dir, + len = fill_pathname_join_special(log_file_path, log_file_dir, content_name, sizeof(log_file_path)); log_file_path[len ] = '.'; log_file_path[len+1] = 'l'; diff --git a/tasks/task_autodetect.c b/tasks/task_autodetect.c index e1f72a5263..ffda510de7 100644 --- a/tasks/task_autodetect.c +++ b/tasks/task_autodetect.c @@ -654,7 +654,8 @@ bool input_autoconfigure_connect( { char dir_driver_autoconfig[PATH_MAX_LENGTH]; /* Generate driver-specific autoconfig directory */ - fill_pathname_join(dir_driver_autoconfig, dir_autoconfig, + fill_pathname_join_special(dir_driver_autoconfig, + dir_autoconfig, autoconfig_handle->device_info.joypad_driver, sizeof(dir_driver_autoconfig)); diff --git a/tasks/task_content.c b/tasks/task_content.c index 5d609dca84..008281acf1 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -1064,7 +1064,7 @@ static bool content_file_load( strlcpy(new_basedir, uwp_dir_data, sizeof(new_basedir)); } } - fill_pathname_join(new_path, new_basedir, + fill_pathname_join_special(new_path, new_basedir, path_basename(content_path), sizeof(new_path)); mbstowcs(wnew_path, new_path, MAX_PATH); diff --git a/tasks/task_content_disc.c b/tasks/task_content_disc.c index 5b1c548794..18b723ffe8 100755 --- a/tasks/task_content_disc.c +++ b/tasks/task_content_disc.c @@ -163,7 +163,7 @@ static void task_cdrom_dump_handler(retro_task_t *task) strlcpy(cue_filename, state->title, sizeof(cue_filename)); strlcat(cue_filename, ".cue", sizeof(cue_filename)); - fill_pathname_join(output_file, + fill_pathname_join_special(output_file, directory_core_assets, cue_filename, sizeof(output_file)); { @@ -261,7 +261,7 @@ static void task_cdrom_dump_handler(retro_task_t *task) state->cur_track_bytes = filestream_get_size(state->file); - fill_pathname_join(output_path, + fill_pathname_join_special(output_path, directory_core_assets, track_filename, sizeof(output_path)); if (!(state->output_file = filestream_open(output_path, RETRO_VFS_FILE_ACCESS_WRITE, 0))) diff --git a/tasks/task_core_updater.c b/tasks/task_core_updater.c index d9cfa80134..9dcb52ff03 100644 --- a/tasks/task_core_updater.c +++ b/tasks/task_core_updater.c @@ -314,7 +314,7 @@ static void task_core_updater_get_list_handler(retro_task_t *task) if (string_is_empty(net_buildbot_url)) goto task_finished; - fill_pathname_join( + fill_pathname_join_special( buildbot_url, net_buildbot_url, ".index-extended", @@ -1042,7 +1042,7 @@ void *task_push_core_updater_download( if (string_is_empty(path_dir_libretro)) goto error; - fill_pathname_join( + fill_pathname_join_special( local_download_path, path_dir_libretro, list_entry->remote_filename, diff --git a/tasks/task_database.c b/tasks/task_database.c index bf1b4794da..0e8062ecde 100644 --- a/tasks/task_database.c +++ b/tasks/task_database.c @@ -753,7 +753,7 @@ static int database_info_list_iterate_found_match( strlcat(db_playlist_base_str, ".lpl", str_len); if (!string_is_empty(_db->playlist_directory)) - fill_pathname_join(db_playlist_path, _db->playlist_directory, + fill_pathname_join_special(db_playlist_path, _db->playlist_directory, db_playlist_base_str, str_len); playlist_config_set_path(&_db->playlist_config, db_playlist_path); @@ -986,7 +986,7 @@ static int task_database_iterate_playlist_lutro( db_playlist_path[0] = '\0'; if (!string_is_empty(_db->playlist_directory)) - fill_pathname_join(db_playlist_path, + fill_pathname_join_special(db_playlist_path, _db->playlist_directory, "Lutro.lpl", sizeof(db_playlist_path)); diff --git a/tasks/task_database_cue.c b/tasks/task_database_cue.c index 5ba229063d..5ebfd6f19a 100644 --- a/tasks/task_database_cue.c +++ b/tasks/task_database_cue.c @@ -1083,7 +1083,7 @@ int cue_find_track(const char *cue_path, bool first, } get_token(fd, tmp_token, sizeof(tmp_token)); - fill_pathname_join(last_file, cue_dir, + fill_pathname_join_special(last_file, cue_dir, tmp_token, sizeof(last_file)); file_size = intfstream_get_file_size(last_file); @@ -1175,7 +1175,8 @@ bool cue_next_file(intfstream_t *fd, if (string_is_equal_noncase(tmp_token, "FILE")) { get_token(fd, tmp_token, sizeof(tmp_token)); - fill_pathname_join(path, cue_dir, tmp_token, (size_t)max_len); + fill_pathname_join_special(path, cue_dir, + tmp_token, (size_t)max_len); rv = true; break; } @@ -1265,15 +1266,11 @@ int gdi_find_track(const char *gdi_path, bool first, char last_file[PATH_MAX_LENGTH]; char gdi_dir[PATH_MAX_LENGTH]; - gdi_dir[0] = last_file[0] = '\0'; - fill_pathname_basedir(gdi_dir, gdi_path, sizeof(gdi_dir)); - - fill_pathname_join(last_file, + fill_pathname_join_special(last_file, gdi_dir, tmp_token, sizeof(last_file)); - file_size = intfstream_get_file_size(last_file); - if (file_size < 0) + if ((file_size = intfstream_get_file_size(last_file)) < 0) goto error; if ((uint64_t)file_size > largest) @@ -1332,11 +1329,8 @@ bool gdi_next_file(intfstream_t *fd, const char *gdi_path, { char gdi_dir[PATH_MAX_LENGTH]; - gdi_dir[0] = '\0'; - fill_pathname_basedir(gdi_dir, gdi_path, sizeof(gdi_dir)); - - fill_pathname_join(path, gdi_dir, tmp_token, (size_t)max_len); + fill_pathname_join_special(path, gdi_dir, tmp_token, (size_t)max_len); rv = true; diff --git a/tasks/task_decompress.c b/tasks/task_decompress.c index 044e568ce9..78e0a90f1f 100644 --- a/tasks/task_decompress.c +++ b/tasks/task_decompress.c @@ -55,7 +55,7 @@ static int file_decompressed_subdir(const char *name, name += strlen(userdata->dec->subdir) + 1; - fill_pathname_join(path, + fill_pathname_join_special(path, userdata->dec->target_dir, name, sizeof(path)); fill_pathname_basedir(path_dir, path, sizeof(path_dir)); @@ -89,13 +89,13 @@ static int file_decompressed(const char *name, const char *valid_exts, if (last_char == '/' || last_char == '\\') return 1; /* Make directory */ - fill_pathname_join(path, dec->target_dir, name, sizeof(path)); + fill_pathname_join_special(path, dec->target_dir, name, sizeof(path)); path_basedir_wrapper(path); if (!path_mkdir(path)) goto error; - fill_pathname_join(path, dec->target_dir, name, sizeof(path)); + fill_pathname_join_special(path, dec->target_dir, name, sizeof(path)); if (!file_archive_perform_mode(path, valid_exts, cdata, cmode, csize, size, crc32, userdata)) diff --git a/tasks/task_pl_thumbnail_download.c b/tasks/task_pl_thumbnail_download.c index 72eba1d756..b81f849c2b 100644 --- a/tasks/task_pl_thumbnail_download.c +++ b/tasks/task_pl_thumbnail_download.c @@ -141,10 +141,10 @@ static bool get_thumbnail_paths( system_name = db_name; /* Generate local path */ - fill_pathname_join(path, pl_thumb->dir_thumbnails, + fill_pathname_join_special(path, pl_thumb->dir_thumbnails, system_name, path_size); - fill_pathname_join(tmp_buf, path, sub_dir, sizeof(tmp_buf)); - fill_pathname_join(path, tmp_buf, img_name, path_size); + fill_pathname_join_special(tmp_buf, path, sub_dir, sizeof(tmp_buf)); + fill_pathname_join_special(path, tmp_buf, img_name, path_size); if (string_is_empty(path)) return false; diff --git a/tasks/task_screenshot.c b/tasks/task_screenshot.c index bdc7069dfe..37d8c932ee 100644 --- a/tasks/task_screenshot.c +++ b/tasks/task_screenshot.c @@ -288,7 +288,7 @@ static bool screenshot_dump( char content_dir_name[PATH_MAX_LENGTH]; fill_pathname_parent_dir_name(content_dir_name, content_dir, sizeof(content_dir_name)); - fill_pathname_join( + fill_pathname_join_special( new_screenshot_dir, screenshot_dir, content_dir_name, @@ -339,7 +339,7 @@ static bool screenshot_dump( fill_pathname_basedir(new_screenshot_dir, name_base, sizeof(new_screenshot_dir)); - fill_pathname_join(state->filename, new_screenshot_dir, + fill_pathname_join_special(state->filename, new_screenshot_dir, state->shotname, sizeof(state->filename)); /* Create screenshot directory, if required */ diff --git a/ui/drivers/qt/qt_playlist.cpp b/ui/drivers/qt/qt_playlist.cpp index 5b2f0cad5b..5c6b563f25 100644 --- a/ui/drivers/qt/qt_playlist.cpp +++ b/ui/drivers/qt/qt_playlist.cpp @@ -1424,10 +1424,9 @@ QString MainWindow::getPlaylistDefaultCore(QString plName) return corePath; /* Get playlist path */ - len = fill_pathname_join( - playlistPath, - settings->paths.directory_playlist, plNameCString, - sizeof(playlistPath)); + len = fill_pathname_join_special( + playlistPath, settings->paths.directory_playlist, + plNameCString, sizeof(playlistPath)); playlistPath[len ] = '.'; playlistPath[len+1] = 'l'; playlistPath[len+2] = 'p'; diff --git a/verbosity.c b/verbosity.c index c54f867608..7443feb37a 100644 --- a/verbosity.c +++ b/verbosity.c @@ -438,7 +438,6 @@ void rarch_log_file_init( static char timestamped_log_file_name[64] = {0}; bool logging_to_file = g_verbosity->initialized; - log_file_path[0] = '\0'; /* If this is the first run, generate a timestamped log * file name (do this even when not outputting timestamped @@ -503,13 +502,15 @@ void rarch_log_file_init( strlcpy(log_directory, log_dir, sizeof(log_directory)); /* Get log file path */ - fill_pathname_join(log_file_path, + fill_pathname_join_special(log_file_path, log_dir, log_to_file_timestamp ? timestamped_log_file_name : "retroarch.log", sizeof(log_file_path)); } + else + log_file_path[0] = '\0'; /* > Attempt to initialise log file */ if (!string_is_empty(log_file_path))