From 8ebedcb6bdb19ec5108bd50de2108f6601b9bee9 Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Mon, 30 Dec 2024 10:07:58 +0100 Subject: [PATCH] (menu_explore) Simplification of explore_load_icons fill_pathname_application_special - return size_t --- file_path_special.c | 44 +++++++++++++++++++++------------------- file_path_special.h | 2 +- gfx/video_shader_parse.c | 2 +- menu/drivers/xmb.c | 2 +- menu/menu_explore.c | 7 +++---- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/file_path_special.c b/file_path_special.c index 68a71eca183..b8167068ff7 100644 --- a/file_path_special.c +++ b/file_path_special.c @@ -189,9 +189,10 @@ bool fill_pathname_application_data(char *s, size_t len) const char* xmb_theme_ident(void); #endif -void fill_pathname_application_special(char *s, +size_t fill_pathname_application_special(char *s, size_t len, enum application_special_type type) { + size_t _len = 0; switch (type) { case APPLICATION_SPECIAL_DIRECTORY_CONFIG: @@ -202,9 +203,9 @@ void fill_pathname_application_special(char *s, /* Try config directory setting first, * fallback to the location of the current configuration file. */ if (!string_is_empty(dir_menu_config)) - strlcpy(s, dir_menu_config, len); + _len = strlcpy(s, dir_menu_config, len); else if (!path_is_empty(RARCH_PATH_CONFIG)) - fill_pathname_basedir(s, path_get(RARCH_PATH_CONFIG), len); + _len = fill_pathname_basedir(s, path_get(RARCH_PATH_CONFIG), len); } break; case APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS: @@ -216,7 +217,7 @@ void fill_pathname_application_special(char *s, const char *dir_assets = settings->paths.directory_assets; fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir)); fill_pathname_join_special(tmp_path, tmp_dir, xmb_theme_ident(), sizeof(tmp_path)); - fill_pathname_join_special(s, tmp_path, "png", len); + _len = fill_pathname_join_special(s, tmp_path, "png", len); } #endif break; @@ -227,7 +228,7 @@ void fill_pathname_application_special(char *s, const char *path_menu_wallpaper = settings->paths.path_menu_wallpaper; if (!string_is_empty(path_menu_wallpaper)) - strlcpy(s, path_menu_wallpaper, len); + _len = strlcpy(s, path_menu_wallpaper, len); else { char tmp_dir[DIR_MAX_LENGTH]; @@ -237,7 +238,7 @@ void fill_pathname_application_special(char *s, fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir)); fill_pathname_join_special(tmp_dir2, tmp_dir, xmb_theme_ident(), sizeof(tmp_dir2)); fill_pathname_join_special(tmp_path, tmp_dir2, "png", sizeof(tmp_path)); - fill_pathname_join_special(s, tmp_path, FILE_PATH_BACKGROUND_IMAGE, len); + _len = fill_pathname_join_special(s, tmp_path, FILE_PATH_BACKGROUND_IMAGE, len); } } #endif @@ -258,7 +259,7 @@ void fill_pathname_application_special(char *s, char tmp_path[PATH_MAX_LENGTH]; fill_pathname_join_special(tmp_dir, dir_assets, menu_ident, sizeof(tmp_dir)); fill_pathname_join_special(tmp_path, tmp_dir, xmb_theme_ident(), sizeof(tmp_path)); - fill_pathname_join_special(s, tmp_path, "sounds", len); + _len = fill_pathname_join_special(s, tmp_path, "sounds", len); } else #endif @@ -268,12 +269,12 @@ void fill_pathname_application_special(char *s, { char tmp_dir[DIR_MAX_LENGTH]; fill_pathname_join_special(tmp_dir, dir_assets, menu_ident, sizeof(tmp_dir)); - fill_pathname_join_special(s, tmp_dir, "sounds", len); + _len = fill_pathname_join_special(s, tmp_dir, "sounds", len); } else #endif { - fill_pathname_join_special( + _len = fill_pathname_join_special( s, dir_assets, "sounds", len); } #endif @@ -296,7 +297,7 @@ void fill_pathname_application_special(char *s, const char *dir_assets = settings->paths.directory_assets; fill_pathname_join_special(tmp_dir, dir_assets, menu_ident, sizeof(tmp_dir)); fill_pathname_join_special(tmp_path, tmp_dir, xmb_theme_ident(), sizeof(tmp_path)); - fill_pathname_join_special(s, tmp_path, "png", len); + _len = fill_pathname_join_special(s, tmp_path, "png", len); } else #endif @@ -317,7 +318,7 @@ void fill_pathname_application_special(char *s, fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir)); fill_pathname_join_special(tmp_path, "monochrome", "png", sizeof(tmp_path)); #endif - fill_pathname_join_special(s, tmp_dir, tmp_path, len); + _len = fill_pathname_join_special(s, tmp_dir, tmp_path, len); } else #endif @@ -342,7 +343,7 @@ void fill_pathname_application_special(char *s, fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir)); fill_pathname_join_special(tmp_path, "monochrome", "png", sizeof(tmp_path)); #endif - fill_pathname_join_special(s, tmp_dir, tmp_path, len); + _len = fill_pathname_join_special(s, tmp_dir, tmp_path, len); } #endif break; @@ -354,7 +355,7 @@ void fill_pathname_application_special(char *s, settings_t *settings = config_get_ptr(); const char *dir_assets = settings->paths.directory_assets; fill_pathname_join_special(tmp_dir, dir_assets, "rgui", sizeof(tmp_dir)); - fill_pathname_join_special(s, tmp_dir, "font", len); + _len = fill_pathname_join_special(s, tmp_dir, "font", len); } #endif break; @@ -366,7 +367,7 @@ void fill_pathname_application_special(char *s, settings_t *settings = config_get_ptr(); const char *dir_assets = settings->paths.directory_assets; fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir)); - fill_pathname_join_special(s, tmp_dir, xmb_theme_ident(), len); + _len = fill_pathname_join_special(s, tmp_dir, xmb_theme_ident(), len); } #endif break; @@ -377,7 +378,7 @@ void fill_pathname_application_special(char *s, const char *path_menu_xmb_font = settings->paths.path_menu_xmb_font; if (!string_is_empty(path_menu_xmb_font)) - strlcpy(s, path_menu_xmb_font, len); + _len = strlcpy(s, path_menu_xmb_font, len); else { char tmp_dir[DIR_MAX_LENGTH]; @@ -388,18 +389,18 @@ void fill_pathname_application_special(char *s, case RETRO_LANGUAGE_PERSIAN: fill_pathname_join_special(tmp_dir, settings->paths.directory_assets, "pkg", sizeof(tmp_dir)); - fill_pathname_join_special(s, tmp_dir, "fallback-font.ttf", len); + _len = fill_pathname_join_special(s, tmp_dir, "fallback-font.ttf", len); break; case RETRO_LANGUAGE_CHINESE_SIMPLIFIED: case RETRO_LANGUAGE_CHINESE_TRADITIONAL: fill_pathname_join_special(tmp_dir, settings->paths.directory_assets, "pkg", sizeof(tmp_dir)); - fill_pathname_join_special(s, tmp_dir, "chinese-fallback-font.ttf", len); + _len = fill_pathname_join_special(s, tmp_dir, "chinese-fallback-font.ttf", len); break; case RETRO_LANGUAGE_KOREAN: fill_pathname_join_special(tmp_dir, settings->paths.directory_assets, "pkg", sizeof(tmp_dir)); - fill_pathname_join_special(s, tmp_dir, "korean-fallback-font.ttf", len); + _len = fill_pathname_join_special(s, tmp_dir, "korean-fallback-font.ttf", len); break; default: { @@ -408,7 +409,7 @@ void fill_pathname_application_special(char *s, const char *dir_assets = settings->paths.directory_assets; fill_pathname_join_special(tmp_dir2, dir_assets, "xmb", sizeof(tmp_dir2)); fill_pathname_join_special(tmp_dir, tmp_dir2, xmb_theme_ident(), sizeof(tmp_dir)); - fill_pathname_join_special(s, tmp_dir, FILE_PATH_TTF_FONT, len); + _len = fill_pathname_join_special(s, tmp_dir, FILE_PATH_TTF_FONT, len); } break; } @@ -422,7 +423,7 @@ void fill_pathname_application_special(char *s, settings_t *settings = config_get_ptr(); const char *dir_thumbnails = settings->paths.directory_thumbnails; fill_pathname_join_special(tmp_dir, dir_thumbnails, "discord", sizeof(tmp_dir)); - fill_pathname_join_special(s, tmp_dir, "avatars", len); + _len = fill_pathname_join_special(s, tmp_dir, "avatars", len); } break; @@ -432,7 +433,7 @@ void fill_pathname_application_special(char *s, settings_t *settings = config_get_ptr(); const char *dir_thumbnails = settings->paths.directory_thumbnails; fill_pathname_join_special(tmp_dir, dir_thumbnails, "cheevos", sizeof(tmp_dir)); - fill_pathname_join_special(s, tmp_dir, "badges", len); + _len = fill_pathname_join_special(s, tmp_dir, "badges", len); } break; @@ -440,4 +441,5 @@ void fill_pathname_application_special(char *s, default: break; } + return _len; } diff --git a/file_path_special.h b/file_path_special.h index 6ffe51fb949..46a536efefb 100644 --- a/file_path_special.h +++ b/file_path_special.h @@ -143,7 +143,7 @@ enum application_special_type bool fill_pathname_application_data(char *s, size_t len); -void fill_pathname_application_special(char *s, size_t len, enum application_special_type type); +size_t fill_pathname_application_special(char *s, size_t len, enum application_special_type type); RETRO_END_DECLS diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 7d88a79d954..d3fe04aedb7 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -1579,7 +1579,7 @@ static bool video_shader_write_referenced_preset( * loaded presets are located * and where Save Game Preset, Save Core Preset, * Save Global Preset save to */ - fill_pathname_application_special(config_dir, DIR_MAX_LENGTH, + fill_pathname_application_special(config_dir, sizeof(config_dir), APPLICATION_SPECIAL_DIRECTORY_CONFIG); /* If there is no initial preset path loaded */ diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 8d78f66c93f..676cfb5c37c 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -1139,7 +1139,7 @@ static void xmb_render_messagebox_internal( string_list_deinitialize(&list); } -static char* xmb_path_dynamic_wallpaper(xmb_handle_t *xmb) +static char *xmb_path_dynamic_wallpaper(xmb_handle_t *xmb) { char path[PATH_MAX_LENGTH]; settings_t *settings = config_get_ptr(); diff --git a/menu/menu_explore.c b/menu/menu_explore.c index 6276bb546d6..a7e0554824d 100644 --- a/menu/menu_explore.c +++ b/menu/menu_explore.c @@ -426,10 +426,10 @@ static void explore_load_icons(explore_state_t *state) { struct texture_image ti; size_t __len = _len; - __len += strlcpy(path + _len, + __len += fill_pathname(path + _len, state->by[EXPLORE_BY_SYSTEM][i]->str, + ".png", sizeof(path) - _len); - strlcpy(path + __len, ".png", sizeof(path) - __len); if (!path_is_valid(path)) continue; @@ -1680,8 +1680,7 @@ SKIP_ENTRY:; const struct playlist_entry *pl_entry = state->entries[current_type - EXPLORE_TYPE_FIRSTITEM].playlist_entry; - strlcpy(state->title, - pl_entry->label, sizeof(state->title)); + strlcpy(state->title, pl_entry->label, sizeof(state->title)); for (pl_idx = 0; pl_idx != (int)RBUF_LEN(state->playlists); pl_idx++) {