From 2cfdccc08555d4ac036e7bca3718019ea0abc085 Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Tue, 24 Dec 2024 18:46:22 +0100 Subject: [PATCH] Less string intermediary copies --- command.c | 178 ++++++++++++++++---------------------- configuration.c | 55 +++++------- core_info.c | 23 ++--- core_info.h | 2 +- manual_content_scan.c | 99 ++++++--------------- menu/menu_displaylist.c | 184 ++++++++++++++++++---------------------- retroarch.c | 182 ++++++++++++--------------------------- retroarch.h | 2 +- runloop.c | 21 ++--- 9 files changed, 278 insertions(+), 468 deletions(-) diff --git a/command.c b/command.c index 035c350887..39e647f92b 100644 --- a/command.c +++ b/command.c @@ -408,7 +408,8 @@ bool command_get_config_param(command_t *cmd, const char* arg) input_driver_state_t *input_st = input_state_get_ptr(); value = value_dynamic; value_dynamic[0] = '\0'; - if(input_st->bsv_movie_state_handle) { + if (input_st->bsv_movie_state_handle) + { bsv_movie_t *movie = input_st->bsv_movie_state_handle; snprintf(value_dynamic, sizeof(value_dynamic), "%lld %u %lld", (long long)(movie->identifier), @@ -741,7 +742,7 @@ bool command_play_replay_slot(command_t *cmd, const char *arg) { input_driver_state_t *input_st = input_state_get_ptr(); task_queue_wait(NULL,NULL); - if(input_st->bsv_movie_state_next_handle) + if (input_st->bsv_movie_state_next_handle) snprintf(reply, sizeof(reply) - 1, "PLAY_REPLAY_SLOT %lld", (long long)(input_st->bsv_movie_state_next_handle->identifier)); else snprintf(reply, sizeof(reply) - 1, "PLAY_REPLAY_SLOT 0"); @@ -827,7 +828,6 @@ bool command_version(command_t *cmd, const char* arg) reply[ _len] = '\n'; reply[++_len] = '\0'; cmd->replier(cmd, reply, _len); - return true; } @@ -883,24 +883,21 @@ static const rarch_memory_descriptor_t* command_memory_get_descriptor(const rarc static uint8_t *command_memory_get_pointer( const rarch_system_info_t* sys_info, - unsigned address, - unsigned int* max_bytes, - int for_write, - char *reply_at, - size_t len) + unsigned address, unsigned int* max_bytes, + int for_write, char *s, size_t len) { if (!sys_info || sys_info->mmaps.num_descriptors == 0) - strlcpy(reply_at, " -1 no memory map defined\n", len); + strlcpy(s, " -1 no memory map defined\n", len); else { size_t offset; const rarch_memory_descriptor_t* desc = command_memory_get_descriptor(&sys_info->mmaps, address, &offset); if (!desc) - strlcpy(reply_at, " -1 no descriptor for address\n", len); + strlcpy(s, " -1 no descriptor for address\n", len); else if (!desc->core.ptr) - strlcpy(reply_at, " -1 no data for descriptor\n", len); + strlcpy(s, " -1 no data for descriptor\n", len); else if (for_write && (desc->core.flags & RETRO_MEMDESC_CONST)) - strlcpy(reply_at, " -1 descriptor data is readonly\n", len); + strlcpy(s, " -1 descriptor data is readonly\n", len); else { *max_bytes = (unsigned int)(desc->core.len - offset); @@ -921,30 +918,28 @@ bool command_get_status(command_t *cmd, const char* arg) if (flags & CONTENT_ST_FLAG_IS_INITED) { /* add some content info */ - runloop_state_t *runloop_st = runloop_state_get_ptr(); - const char *content_name = path_basename(path_get(RARCH_PATH_BASENAME)); /* filename only without ext */ - int content_crc32 = content_get_crc(); - const char* system_id = NULL; core_info_t *core_info = NULL; - - reply[0] = '\0'; + runloop_state_t *runloop_st = runloop_state_get_ptr(); core_info_get_current_core(&core_info); - if (core_info) - system_id = core_info->system_id; - if (!system_id) - system_id = runloop_st->system.info.library_name; - _len = strlcpy(reply, "GET_STATUS ", sizeof(reply)); + _len = strlcpy(reply, "GET_STATUS ", sizeof(reply)); if (runloop_st->flags & RUNLOOP_FLAG_PAUSED) - _len += strlcpy(reply + _len, "PAUSED", sizeof(reply) - _len); + _len += strlcpy(reply + _len, "PAUSED", sizeof(reply) - _len); else _len += strlcpy(reply + _len, "PLAYING", sizeof(reply) - _len); - _len += strlcpy(reply + _len, " ", sizeof(reply) - _len); - _len += strlcpy(reply + _len, system_id, sizeof(reply) - _len); - _len += strlcpy(reply + _len, ",", sizeof(reply) - _len); - _len += strlcpy(reply + _len, content_name, sizeof(reply) - _len); - _len += snprintf(reply + _len, sizeof(reply) - _len, ",crc32=%x\n", content_crc32); + _len += strlcpy(reply + _len, " ", sizeof(reply) - _len); + if (core_info) + _len += strlcpy(reply + _len, core_info->system_id, + sizeof(reply) - _len); + else + _len += strlcpy(reply + _len, runloop_st->system.info.library_name, + sizeof(reply) - _len); + _len += strlcpy(reply + _len, ",", sizeof(reply) - _len); + _len += strlcpy(reply + _len, + path_basename(path_get(RARCH_PATH_BASENAME)), sizeof(reply) - _len); + _len += snprintf(reply + _len, sizeof(reply) - _len, + ",crc32=%x\n", content_get_crc()); } else _len = strlcpy(reply, "GET_STATUS CONTENTLESS", sizeof(reply)); @@ -1167,8 +1162,7 @@ void command_event_init_controllers(rarch_system_info_t *sys_info, #ifdef HAVE_CONFIGFILE bool command_event_save_config( - const char *config_path, - char *s, size_t len) + const char *config_path, char *s, size_t len) { bool path_exists = !string_is_empty(config_path); const char *str = path_exists ? config_path : @@ -1289,8 +1283,7 @@ bool command_event_save_auto_state(void) _len = strlcpy(savestate_name_auto, runloop_st->name.savestate, sizeof(savestate_name_auto)); - strlcpy(savestate_name_auto + _len, - ".auto", + strlcpy(savestate_name_auto + _len, ".auto", sizeof(savestate_name_auto) - _len); if (content_auto_save_state((const char*)savestate_name_auto)) @@ -1401,8 +1394,7 @@ void command_event_load_auto_state(void) _len = strlcpy(savestate_name_auto, runloop_st->name.savestate, sizeof(savestate_name_auto)); - strlcpy(savestate_name_auto + _len, - ".auto", + strlcpy(savestate_name_auto + _len, ".auto", sizeof(savestate_name_auto) - _len); if (!path_is_valid(savestate_name_auto)) @@ -1429,11 +1421,16 @@ void command_event_load_auto_state(void) * * @param settings The usual RetroArch settings ptr. * @param last_index Return value for load slot. - * @param file_to_delete Return value for file name that should be removed. + * @param @s Return value for file name that should be removed. */ static void scan_states(settings_t *settings, - unsigned *last_index, char *file_to_delete) + unsigned *last_index, char *s) { + /* Base name of 128 may be too short for some (<<1%) of the + tosec-based file names, but in practice truncating will not + lead to mismatch */ + char state_base[128]; + char state_dir[DIR_MAX_LENGTH]; runloop_state_t *runloop_st = runloop_state_get_ptr(); bool show_hidden_files = settings->bools.show_hidden_files; unsigned savestate_max_keep = settings->uints.savestate_max_keep; @@ -1452,19 +1449,12 @@ static void scan_states(settings_t *settings, size_t i, cnt = 0; size_t cnt_in_range = 0; - char state_dir[DIR_MAX_LENGTH]; - /* Base name of 128 may be too short for some (<<1%) of the - tosec-based file names, but in practice truncating will not - lead to mismatch */ - char state_base[128]; fill_pathname_basedir(state_dir, runloop_st->name.savestate, sizeof(state_dir)); - dir_list = dir_list_new_special(state_dir, DIR_LIST_PLAIN, NULL, - show_hidden_files); - - if (!dir_list) + if (!(dir_list = dir_list_new_special(state_dir, + DIR_LIST_PLAIN, NULL, show_hidden_files))) return; fill_pathname_base(state_base, runloop_st->name.savestate, @@ -1473,7 +1463,7 @@ static void scan_states(settings_t *settings, for (i = 0; i < dir_list->size; i++) { unsigned idx; - char elem_base[128] = {0}; + char elem_base[128]; const char *ext = NULL; const char *end = NULL; const char *dir_elem = dir_list->elems[i].data; @@ -1486,8 +1476,8 @@ static void scan_states(settings_t *settings, /* Only consider files with a '.state' extension * > i.e. Ignore '.state.auto', '.state.bak', etc. */ ext = path_get_extension(elem_base); - if (string_is_empty(ext) || - !string_starts_with_size(ext, "state", STRLEN_CONST("state"))) + if ( string_is_empty(ext) + || !string_starts_with_size(ext, "state", STRLEN_CONST("state"))) continue; /* Check whether this file is associated with @@ -1499,7 +1489,7 @@ static void scan_states(settings_t *settings, /* Save filename root and length (once) */ if (savefile_root_length == 0) { - savefile_root = dir_elem; + savefile_root = dir_elem; savefile_root_length = strlen(dir_elem); } @@ -1521,30 +1511,28 @@ static void scan_states(settings_t *settings, cnt_in_range++; /* Maintain a 2x512 bit map of occupied save states */ - if (idx<512) + if (idx < 512) BIT512_SET(slot_mapping_low,idx); - else if (idx<1024) + else if (idx < 1024) BIT512_SET(slot_mapping_high,idx-512); } /* Next loop on the bitmap, since the file system may have presented the files in any order above */ - for(i=0 ; i <= savestate_max_keep ; i++) + for (i = 0; i <= savestate_max_keep; i++) { /* Unoccupied save slots */ - if ((i < 512 && !BIT512_GET(slot_mapping_low, i)) || - (i > 511 && !BIT512_GET(slot_mapping_high, i-512)) ) + if ( (i < 512 && !BIT512_GET(slot_mapping_low, i)) + || (i > 511 && !BIT512_GET(slot_mapping_high, i-512))) { /* Gap index: lowest free slot in the wraparound range */ if (gap_idx == UINT_MAX) gap_idx = (unsigned)i; } - /* Occupied save slots */ - else + else /* Occupied save slots */ { /* Del index: first occupied slot in the wraparound range, after gap index */ - if (gap_idx < UINT_MAX && - del_idx == UINT_MAX) + if ( gap_idx < UINT_MAX && del_idx == UINT_MAX) del_idx = (unsigned)i; } } @@ -1561,8 +1549,8 @@ static void scan_states(settings_t *settings, * higher up -> load that */ else loa_idx = max_idx; - gap_idx = savestate_max_keep; - del_idx = savestate_max_keep; + gap_idx = savestate_max_keep; + del_idx = savestate_max_keep; } /* No gap was found - deduct from current index or default and set (missing) gap index to be deleted */ @@ -1587,18 +1575,16 @@ static void scan_states(settings_t *settings, loa_idx = savestate_max_keep; gap_idx = 0; } - del_idx = gap_idx; + del_idx = gap_idx; } /* Gap was found */ else { /* No candidate to delete */ + /* Either gap is at the end of the range: wraparound. + or there is no better idea than the lowest index */ if (del_idx == UINT_MAX) - { - /* Either gap is at the end of the range: wraparound. - or there is no better idea than the lowest index */ del_idx = 0; - } /* Adjust load index */ if (gap_idx == 0) loa_idx = savestate_max_keep; @@ -1610,16 +1596,16 @@ static void scan_states(settings_t *settings, "%d (%d), max:%d, load index %d, gap index %d, delete index %d\n", cnt, cnt_in_range, max_idx, loa_idx, gap_idx, del_idx); - if (last_index != NULL) - { + if (last_index) *last_index = loa_idx; - } - if (file_to_delete != NULL && cnt_in_range >= savestate_max_keep) + + if ( s + && cnt_in_range >= savestate_max_keep) { - strlcpy(file_to_delete, savefile_root, savefile_root_length + 1); + strlcpy(s, savefile_root, savefile_root_length + 1); /* ".state0" is just ".state" instead, so don't print that. */ if (del_idx > 0) - snprintf(file_to_delete+savefile_root_length, 5, "%d", del_idx); + snprintf(s + savefile_root_length, 5, "%d", del_idx); } dir_list_free(dir_list); @@ -1638,12 +1624,11 @@ int command_event_get_next_savestate_auto_index(settings_t *settings) { unsigned savestate_max_keep = settings->uints.savestate_max_keep; int new_state_slot = settings->ints.state_slot + 1; - /* If previous save was above the wraparound range, or it overflows, return to the start of the range. */ - if( savestate_max_keep > 0 && (unsigned)new_state_slot > savestate_max_keep) - new_state_slot = 0; - + if ( (savestate_max_keep > 0) + && (unsigned)new_state_slot > savestate_max_keep) + return 0; return new_state_slot; } @@ -1655,15 +1640,12 @@ int command_event_get_next_savestate_auto_index(settings_t *settings) */ void command_event_set_savestate_auto_index(settings_t *settings) { - unsigned max_idx = 0; - bool savestate_auto_index = settings->bools.savestate_auto_index; - + unsigned max_idx = 0; + bool savestate_auto_index = settings->bools.savestate_auto_index; if (!savestate_auto_index) return; - scan_states(settings, &max_idx, NULL); configuration_set_int(settings, settings->ints.state_slot, max_idx); - RARCH_LOG("[State]: %s: #%d\n", msg_hash_to_str(MSG_FOUND_LAST_STATE_SLOT), max_idx); @@ -1676,9 +1658,8 @@ void command_event_set_savestate_auto_index(settings_t *settings) */ static void command_event_set_savestate_garbage_collect(settings_t *settings) { - char state_to_delete[PATH_MAX_LENGTH] = {0}; size_t i; - + char state_to_delete[PATH_MAX_LENGTH] = {0}; scan_states(settings, NULL, state_to_delete); /* Only delete one save state per save action * > Conservative behaviour, designed to minimise @@ -1720,10 +1701,8 @@ void command_event_set_replay_auto_index(settings_t *settings) fill_pathname_basedir(state_dir, runloop_st->name.replay, sizeof(state_dir)); - dir_list = dir_list_new_special(state_dir, DIR_LIST_PLAIN, NULL, - show_hidden_files); - - if (!dir_list) + if (!(dir_list = dir_list_new_special(state_dir, + DIR_LIST_PLAIN, NULL, show_hidden_files))) return; fill_pathname_base(state_base, runloop_st->name.replay, @@ -1768,8 +1747,8 @@ void command_event_set_replay_garbage_collect( { /* TODO: debugme */ size_t i, cnt = 0; - char state_dir[DIR_MAX_LENGTH]; char state_base[128]; + char state_dir[DIR_MAX_LENGTH]; runloop_state_t *runloop_st = runloop_state_get_ptr(); struct string_list *dir_list = NULL; @@ -1781,10 +1760,8 @@ void command_event_set_replay_garbage_collect( fill_pathname_basedir(state_dir, runloop_st->name.replay, sizeof(state_dir)); - dir_list = dir_list_new_special(state_dir, DIR_LIST_PLAIN, NULL, - show_hidden_files); - - if (!dir_list) + if (!(dir_list = dir_list_new_special(state_dir, + DIR_LIST_PLAIN, NULL, show_hidden_files))) return; fill_pathname_base(state_base, runloop_st->name.replay, @@ -1806,8 +1783,8 @@ void command_event_set_replay_garbage_collect( /* Only consider files with a '.replayXX' extension * > i.e. Ignore '.replay.auto', '.replay.bak', etc. */ ext = path_get_extension(elem_base); - if (string_is_empty(ext) || - !string_starts_with_size(ext, "replay", STRLEN_CONST("REPLAY"))) + if ( string_is_empty(ext) + || !string_starts_with_size(ext, "replay", STRLEN_CONST("REPLAY"))) continue; /* Check whether this file is associated with @@ -1879,9 +1856,9 @@ bool command_event_save_core_config( const char *rarch_path_config) { char msg[128]; + char config_dir[DIR_MAX_LENGTH]; char config_path[PATH_MAX_LENGTH]; char config_name[NAME_MAX_LENGTH]; - char config_dir[DIR_MAX_LENGTH]; bool new_path_available = false; bool overrides_active = false; const char *core_path = NULL; @@ -2002,10 +1979,8 @@ void command_event_save_current_config(enum override_type type) case OVERRIDE_CORE: case OVERRIDE_CONTENT_DIR: { - int8_t ret = config_save_overrides(type, &runloop_st->system, false, NULL); char msg[256]; - - msg[0] = '\0'; + int8_t ret = config_save_overrides(type, &runloop_st->system, false, NULL); switch (ret) { @@ -2053,17 +2028,14 @@ void command_event_remove_current_config(enum override_type type) case OVERRIDE_CONTENT_DIR: { char msg[256]; - - msg[0] = '\0'; - if (config_save_overrides(type, &runloop_st->system, true, NULL)) strlcpy(msg, msg_hash_to_str(MSG_OVERRIDES_REMOVED_SUCCESSFULLY), sizeof(msg)); else strlcpy(msg, msg_hash_to_str(MSG_OVERRIDES_ERROR_REMOVING), sizeof(msg)); RARCH_LOG("[Overrides]: %s\n", msg); - runloop_msg_queue_push(msg, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); - + runloop_msg_queue_push(msg, 1, 180, true, NULL, + MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); #ifdef HAVE_MENU { struct menu_state *menu_st = menu_state_get_ptr(); diff --git a/configuration.c b/configuration.c index 21e35a90e7..a52fe683cd 100644 --- a/configuration.c +++ b/configuration.c @@ -1471,31 +1471,27 @@ const char *config_get_all_timezones(void) return char_list_new_special(STRING_LIST_TIMEZONES, NULL); } -static void load_timezone(char *s) +static void load_timezone(char *s, size_t len) { char haystack[TIMEZONE_LENGTH+32]; - static char *needle = "TIMEZONE="; RFILE *tzfp = filestream_open(LAKKA_TIMEZONE_PATH, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE); if (tzfp) { - char *start = NULL; + static char *needle = "TIMEZONE="; + char *start = NULL; filestream_gets(tzfp, haystack, sizeof(haystack)-1); filestream_close(tzfp); if ((start = strstr(haystack, needle))) - { - size_t needle_len = STRLEN_CONST("TIMEZONE="); - strlcpy(s, start + needle_len, TIMEZONE_LENGTH); - } + strlcpy(s, start + STRLEN_CONST("TIMEZONE="), len); else - strlcpy(s, DEFAULT_TIMEZONE, TIMEZONE_LENGTH); + strlcpy(s, DEFAULT_TIMEZONE, len); } else - strlcpy(s, DEFAULT_TIMEZONE, TIMEZONE_LENGTH); - + strlcpy(s, DEFAULT_TIMEZONE, len); config_set_timezone(s); } #endif @@ -1547,19 +1543,10 @@ static struct config_array_setting *populate_settings_array( for (i = 0; i < MAX_USERS; i++) { - size_t _len; - char formatted_number[4]; - char prefix[16]; char key[32]; - - formatted_number[0] = '\0'; - - snprintf(formatted_number, sizeof(formatted_number), "%u", i + 1); - _len = strlcpy(prefix, "input_player", sizeof(prefix)); - strlcpy(prefix + _len, formatted_number, sizeof(prefix) - _len); - _len = strlcpy(key, prefix, sizeof(key)); + size_t _len = strlcpy(key, "input_player", sizeof(key)); + _len += snprintf(key + _len, sizeof(key) - _len, "%u", i + 1); strlcpy(key + _len, "_reserved_device", sizeof(key) - _len); - SETTING_ARRAY(strdup(key), settings->arrays.input_reserved_devices[i], false, NULL, true); } @@ -2947,7 +2934,7 @@ void config_set_defaults(void *data) configuration_set_bool(settings, settings->bools.bluetooth_enable, filestream_exists(LAKKA_BLUETOOTH_PATH)); configuration_set_bool(settings, settings->bools.localap_enable, false); - load_timezone(settings->arrays.timezone); + load_timezone(settings->arrays.timezone, TIMEZONE_LENGTH); #endif #if __APPLE__ @@ -4393,7 +4380,7 @@ bool config_load_override(void *data) /* Create a new config file from core_path */ if (path_is_valid(core_path)) { - char tmp_path[PATH_MAX_LENGTH + 1]; + char tmp_path[PATH_MAX_LENGTH]; RARCH_LOG("[Overrides]: Core-specific overrides found at \"%s\".\n", core_path); @@ -4423,7 +4410,7 @@ bool config_load_override(void *data) /* Create a new config file from content_path */ if (path_is_valid(content_path)) { - char tmp_path[PATH_MAX_LENGTH + 1]; + char tmp_path[PATH_MAX_LENGTH]; RARCH_LOG("[Overrides]: Content dir-specific overrides found at \"%s\".\n", content_path); @@ -4451,7 +4438,7 @@ bool config_load_override(void *data) /* Create a new config file from game_path */ if (path_is_valid(game_path)) { - char tmp_path[PATH_MAX_LENGTH + 1]; + char tmp_path[PATH_MAX_LENGTH]; RARCH_LOG("[Overrides]: Game-specific overrides found at \"%s\".\n", game_path); @@ -4659,12 +4646,14 @@ bool config_load_remap(const char *directory_input_remapping, ) { /* Ensure directory does not contain special chars */ - const char *inp_dev_dir = sanitize_path_part(inp_dev_name, strlen(inp_dev_name)); + const char *inp_dev_dir = sanitize_path_part( + inp_dev_name, strlen(inp_dev_name)); /* Build the new path with the controller name */ size_t _len = strlcpy(remap_path, core_name, sizeof(remap_path)); - _len += strlcpy(remap_path + _len, PATH_DEFAULT_SLASH(), sizeof(remap_path) - _len); - _len += strlcpy(remap_path + _len, inp_dev_dir, sizeof(remap_path) - _len); - + _len += strlcpy(remap_path + _len, PATH_DEFAULT_SLASH(), + sizeof(remap_path) - _len); + _len += strlcpy(remap_path + _len, inp_dev_dir, + sizeof(remap_path) - _len); /* Deallocate as we no longer this */ free((char*)inp_dev_dir); inp_dev_dir = NULL; @@ -5103,13 +5092,9 @@ void config_get_autoconf_profile_filename( /* Driver specific autoconf dir may not exist, if autoconfs are not downloaded. */ if (!path_is_directory(buf)) - { len = strlcpy(buf, sanitised_name, len_buf); - } else - { len = fill_pathname_join_special(buf, joypad_driver, sanitised_name, len_buf); - } strlcpy(buf + len, ".cfg", len_buf - len); end: @@ -6047,8 +6032,8 @@ bool input_remapping_save_file(const char *path) return false; /* Create output directory, if required */ - _len = strlcpy(remap_file_dir, path, sizeof(remap_file_dir)); - path_parent_dir(remap_file_dir, _len); + fill_pathname_parent_dir(remap_file_dir, path, + sizeof(remap_file_dir)); if ( !string_is_empty(remap_file_dir) && !path_is_directory(remap_file_dir) diff --git a/core_info.c b/core_info.c index ba8ec17621..001dc71ffb 100644 --- a/core_info.c +++ b/core_info.c @@ -2617,27 +2617,18 @@ bool core_info_database_supports_content_path( return false; } -bool core_info_list_get_display_name( +size_t core_info_list_get_display_name( core_info_list_t *core_info_list, const char *core_path, char *s, size_t len) { - core_info_t *info; - - if (!core_info_list) - return false; - - info = core_info_find_internal( - core_info_list, core_path); - - if ( s - && info - && !string_is_empty(info->display_name)) + if (core_info_list) { - strlcpy(s, info->display_name, len); - return true; + core_info_t *info = core_info_find_internal( + core_info_list, core_path); + if (s && info && !string_is_empty(info->display_name)) + return strlcpy(s, info->display_name, len); } - - return false; + return 0; } /* Returns core_info parameters required for diff --git a/core_info.h b/core_info.h index 15db66abc7..6a5f6422d9 100644 --- a/core_info.h +++ b/core_info.h @@ -155,7 +155,7 @@ typedef struct core_info_state core_info_state_t; void core_info_list_get_supported_cores(core_info_list_t *list, const char *path, const core_info_t **infos, size_t *num_infos); -bool core_info_list_get_display_name(core_info_list_t *list, +size_t core_info_list_get_display_name(core_info_list_t *list, const char *core_path, char *s, size_t len); /* Returns core_info parameters required for diff --git a/manual_content_scan.c b/manual_content_scan.c index 1f75205294..0df2c78138 100644 --- a/manual_content_scan.c +++ b/manual_content_scan.c @@ -42,15 +42,15 @@ typedef struct enum manual_content_scan_system_name_type system_name_type; enum manual_content_scan_core_type core_type; - char core_name[NAME_MAX_LENGTH]; - char system_name_database[NAME_MAX_LENGTH]; - char system_name_custom[NAME_MAX_LENGTH]; - char content_dir[DIR_MAX_LENGTH]; - char system_name_content_dir[DIR_MAX_LENGTH]; char core_path[PATH_MAX_LENGTH]; char file_exts_core[PATH_MAX_LENGTH]; char file_exts_custom[PATH_MAX_LENGTH]; char dat_file_path[PATH_MAX_LENGTH]; + char content_dir[DIR_MAX_LENGTH]; + char system_name_content_dir[DIR_MAX_LENGTH]; + char system_name_database[NAME_MAX_LENGTH]; + char system_name_custom[NAME_MAX_LENGTH]; + char core_name[NAME_MAX_LENGTH]; bool search_recursively; bool search_archives; @@ -200,10 +200,8 @@ static void manual_content_scan_scrub_file_exts(char *file_exts) void manual_content_scan_scrub_system_name_custom(void) { char *scrub_char_pointer = NULL; - if (string_is_empty(scan_settings.system_name_custom)) return; - /* Scrub characters that are not cross-platform * and/or violate the No-Intro filename standard: * http://datomatic.no-intro.org/stuff/The%20Official%20No-Intro%20Convention%20(20071030).zip @@ -293,14 +291,11 @@ bool manual_content_scan_set_menu_content_dir(const char *content_dir) if (!path_is_directory(content_dir)) goto error; - /* Copy directory path to settings struct */ - _len = strlcpy( - scan_settings.content_dir, - content_dir, - sizeof(scan_settings.content_dir)); - - /* Remove trailing slash, if required */ - if (_len <= 0) + /* Copy directory path to settings struct. + * Remove trailing slash, if required */ + if ((_len = strlcpy( + scan_settings.content_dir, content_dir, + sizeof(scan_settings.content_dir))) <= 0) goto error; if (scan_settings.content_dir[_len - 1] == PATH_DEFAULT_SLASH_C()) @@ -407,10 +402,10 @@ bool manual_content_scan_set_menu_core_name( } else { + size_t i; core_info_list_t *core_info_list = NULL; core_info_t *core_info = NULL; bool core_found = false; - size_t i; /* We are using a manually set core... */ if (string_is_empty(core_name)) @@ -524,8 +519,6 @@ enum manual_content_scan_playlist_refresh_status playlist_status = MANUAL_CONTENT_SCAN_PLAYLIST_REFRESH_OK; char system_name[NAME_MAX_LENGTH]; - system_name[0] = '\0'; - if (!playlist_scan_refresh_enabled(playlist)) { playlist_status = MANUAL_CONTENT_SCAN_PLAYLIST_REFRESH_MISSING_CONFIG; @@ -587,25 +580,15 @@ enum manual_content_scan_playlist_refresh_status /* Loop over database files */ for (i = 0; i < rdb_list->size; i++) { - const char *rdb_path = rdb_list->elems[i].data; - const char *rdb_file = NULL; char rdb_name[NAME_MAX_LENGTH]; - + const char *rdb_path = rdb_list->elems[i].data; /* Sanity check */ if (string_is_empty(rdb_path)) continue; - - rdb_file = path_basename(rdb_path); - - if (string_is_empty(rdb_file)) - continue; - - fill_pathname(rdb_name, rdb_file, "", + fill_pathname(rdb_name, path_basename(rdb_path), "", sizeof(rdb_name)); - if (string_is_empty(rdb_name)) continue; - /* Check whether playlist system name * matches current database file */ if (string_is_equal(system_name, rdb_name)) @@ -726,12 +709,9 @@ bool manual_content_scan_get_menu_content_dir(const char **content_dir) { if (!content_dir) return false; - if (string_is_empty(scan_settings.content_dir)) return false; - *content_dir = scan_settings.content_dir; - return true; } @@ -847,25 +827,15 @@ struct string_list *manual_content_scan_get_menu_system_name_list( /* Loop over database files */ for (i = 0; i < rdb_list->size; i++) { - const char *rdb_path = rdb_list->elems[i].data; - const char *rdb_file = NULL; char rdb_name[NAME_MAX_LENGTH]; - + const char *rdb_path = rdb_list->elems[i].data; /* Sanity check */ if (string_is_empty(rdb_path)) continue; - - rdb_file = path_basename(rdb_path); - - if (string_is_empty(rdb_file)) - continue; - - fill_pathname(rdb_name, rdb_file, "", + fill_pathname(rdb_name, path_basename(rdb_path), "", sizeof(rdb_name)); - if (string_is_empty(rdb_name)) continue; - /* Add database name to list */ if (!string_list_append(name_list, rdb_name, attr)) goto error; @@ -893,13 +863,13 @@ error: * > Returned string list must be free()'d */ struct string_list *manual_content_scan_get_menu_core_name_list(void) { + union string_list_elem_attr attr; struct string_list *name_list = string_list_new(); core_info_list_t *core_info_list = NULL; - union string_list_elem_attr attr; /* Sanity check */ if (!name_list) - goto error; + return NULL; attr.i = 0; @@ -926,7 +896,6 @@ struct string_list *manual_content_scan_get_menu_core_name_list(void) { if (string_is_empty(core_info->display_name)) continue; - /* Add core name to list */ if (!string_list_append(name_list, core_info->display_name, attr)) goto error; @@ -952,8 +921,7 @@ error: * Returns false if current settings are invalid. */ bool manual_content_scan_get_task_config( manual_content_scan_task_config_t *task_config, - const char *path_dir_playlist - ) + const char *path_dir_playlist) { size_t len; if (!task_config) @@ -1094,7 +1062,6 @@ bool manual_content_scan_get_task_config( { if (!logiqx_dat_path_is_valid(scan_settings.dat_file_path, NULL)) return false; - strlcpy( task_config->dat_file_path, scan_settings.dat_file_path, @@ -1129,7 +1096,6 @@ struct string_list *manual_content_scan_get_content_list( /* Sanity check */ if (!task_config) goto error; - if (string_is_empty(task_config->content_dir)) goto error; @@ -1160,10 +1126,7 @@ struct string_list *manual_content_scan_get_content_list( ); /* Sanity check */ - if (!dir_list) - goto error; - - if (dir_list->size < 1) + if (!dir_list || dir_list->size < 1) goto error; /* Ensure list is in alphabetical order @@ -1191,18 +1154,14 @@ static bool manual_content_scan_get_playlist_content_path( { size_t _len; struct string_list *archive_list = NULL; - /* Sanity check */ if (!task_config || string_is_empty(content_path)) return false; - if (!path_is_valid(content_path)) return false; - /* In all cases, base content path must be * copied to @s */ _len = strlcpy(s, content_path, len); - /* Check whether this is an archive file * requiring special attention... */ if ( (content_type == RARCH_COMPRESSED_ARCHIVE) @@ -1276,7 +1235,7 @@ error: static bool manual_content_scan_get_playlist_content_label( const char *content_path, logiqx_dat_t *dat_file, bool filter_dat_content, - char *content_label, size_t len) + char *s, size_t len) { /* Sanity check */ if (string_is_empty(content_path)) @@ -1284,45 +1243,41 @@ static bool manual_content_scan_get_playlist_content_label( /* In most cases, content label is just the * filename without extension */ - fill_pathname(content_label, path_basename(content_path), + fill_pathname(s, path_basename(content_path), "", len); - if (string_is_empty(content_label)) + if (string_is_empty(s)) return false; /* Check if a DAT file has been specified */ if (dat_file) { - bool content_found = false; logiqx_dat_game_info_t game_info; /* Search for current content * > If content is not listed in DAT file, * use existing filename without extension */ - if (logiqx_dat_search(dat_file, content_label, &game_info)) + if (logiqx_dat_search(dat_file, s, &game_info)) { /* BIOS files should always be skipped */ if (game_info.is_bios) return false; - /* Only include 'runnable' content */ if (!game_info.is_runnable) return false; - /* Copy game description */ if (!string_is_empty(game_info.description)) { - strlcpy(content_label, game_info.description, len); - content_found = true; + strlcpy(s, game_info.description, len); + return true; } } /* If we are applying a DAT file filter, * unlisted content should be skipped */ - if (!content_found && filter_dat_content) + if (filter_dat_content) return false; } - return true; } @@ -1349,8 +1304,8 @@ void manual_content_scan_add_content_to_playlist( * in playlist */ if (!playlist_entry_exists(playlist, playlist_content_path)) { - struct playlist_entry entry = {0}; char label[NAME_MAX_LENGTH]; + struct playlist_entry entry = {0}; label[0] = '\0'; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 3b00251d96..a70d0e0ba1 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -508,7 +508,8 @@ static int filebrowser_parse( else { size_t _len = fill_pathname_home_dir(dir, sizeof(dir)); - if (string_ends_with(full_path, "/") && !string_ends_with(dir, "/")) + if ( string_ends_with(full_path, "/") + && !string_ends_with(dir, "/")) strlcpy(dir + _len, "/", sizeof(dir) - _len); if (string_is_equal(dir, full_path)) allow_parent_directory = false; @@ -1812,10 +1813,8 @@ static unsigned menu_displaylist_parse_supported_cores(menu_displaylist_info_t * static unsigned menu_displaylist_parse_system_info(file_list_t *list) { - char tmp[128]; char entry[NAME_MAX_LENGTH]; unsigned count = 0; - /* RetroArch Version */ size_t _len = strlcpy(entry, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_RETROARCH_VERSION), @@ -1872,7 +1871,7 @@ static unsigned menu_displaylist_parse_system_info(file_list_t *list) perms ? msg_hash_to_str(MSG_READ_WRITE) : msg_hash_to_str(MSG_READ_ONLY), - sizeof(tmp)); + sizeof(entry)); if (menu_entries_append(list, entry, "", MENU_ENUM_LABEL_SYSTEM_INFO_ENTRY, MENU_SETTINGS_CORE_INFO_NONE, 0, 0, NULL)) @@ -1903,14 +1902,13 @@ static unsigned menu_displaylist_parse_system_info(file_list_t *list) } /* CPU Features */ - retroarch_get_capabilities(RARCH_CAPABILITIES_CPU, tmp, sizeof(tmp)); _len = strlcpy(entry, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_CPU_FEATURES), sizeof(entry)); entry[ _len] = ':'; entry[++_len] = ' '; entry[++_len] = '\0'; - strlcpy(entry + _len, tmp, sizeof(entry) - _len); + retroarch_get_capabilities(RARCH_CAPABILITIES_CPU, entry + _len, sizeof(entry) - _len); if (menu_entries_append(list, entry, "", MENU_ENUM_LABEL_SYSTEM_INFO_ENTRY, MENU_SETTINGS_CORE_INFO_NONE, 0, 0, NULL)) @@ -2128,41 +2126,38 @@ static unsigned menu_displaylist_parse_system_info(file_list_t *list) /* Power Source */ if (frontend->get_powerstate) { - size_t _len; int seconds = 0; int percent = 0; enum frontend_powerstate state = frontend->get_powerstate(&seconds, &percent); - - /* N/A */ - if (state == FRONTEND_POWERSTATE_NONE) - strlcpy(tmp, - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), - sizeof(tmp)); - /* n% (No Source) */ - else if (state == FRONTEND_POWERSTATE_NO_SOURCE) - snprintf(tmp, sizeof(tmp), "%d%% (%s)", percent, - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE_NO_SOURCE)); - /* n% (Charging) */ - else if (state == FRONTEND_POWERSTATE_CHARGING) - snprintf(tmp, sizeof(tmp), "%d%% (%s)", percent, - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE_CHARGING)); - /* n% (Charged) */ - else if (state == FRONTEND_POWERSTATE_CHARGED) - snprintf(tmp, sizeof(tmp), "%d%% (%s)", percent, - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE_CHARGED)); - /* n% (Discharging) */ - else if (state == FRONTEND_POWERSTATE_ON_POWER_SOURCE) - snprintf(tmp, sizeof(tmp), "%d%% (%s)", percent, - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE_DISCHARGING)); - /* Power Source */ - _len = strlcpy(entry, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE), + size_t _len = strlcpy(entry, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE), sizeof(entry)); entry[ _len] = ':'; entry[++_len] = ' '; entry[++_len] = '\0'; - strlcpy(entry + _len, tmp, sizeof(entry) - _len); + /* N/A */ + if (state == FRONTEND_POWERSTATE_NONE) + strlcpy(entry + _len, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), + sizeof(entry) - _len); + /* n% (No Source) */ + else if (state == FRONTEND_POWERSTATE_NO_SOURCE) + snprintf(entry + _len, sizeof(entry) - _len, "%d%% (%s)", percent, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE_NO_SOURCE)); + /* n% (Charging) */ + else if (state == FRONTEND_POWERSTATE_CHARGING) + snprintf(entry + _len, sizeof(entry) - _len, "%d%% (%s)", percent, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE_CHARGING)); + /* n% (Charged) */ + else if (state == FRONTEND_POWERSTATE_CHARGED) + snprintf(entry + _len, sizeof(entry) - _len, "%d%% (%s)", percent, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE_CHARGED)); + /* n% (Discharging) */ + else if (state == FRONTEND_POWERSTATE_ON_POWER_SOURCE) + snprintf(entry + _len, sizeof(entry) - _len, "%d%% (%s)", percent, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE_DISCHARGING)); if (menu_entries_append(list, entry, "", MENU_ENUM_LABEL_SYSTEM_INFO_ENTRY, MENU_SETTINGS_CORE_INFO_NONE, 0, 0, NULL)) @@ -2653,24 +2648,15 @@ static int create_string_list_rdb_entry_string( size_t path_len, file_list_t *list) { - size_t _len; char tmp[128]; - char *out_lbl = NULL; - size_t str_len = (strlen(label) + 1) - + (strlen(actual_string) + 1) - + (path_len + 1); - - if (!(out_lbl = (char*)calloc(str_len, sizeof(char)))) - return -1; - - _len = strlcpy(out_lbl, label, str_len); + char out_lbl[NAME_MAX_LENGTH]; + size_t _len = strlcpy(out_lbl, label, sizeof(out_lbl)); out_lbl[ _len] = '|'; out_lbl[++_len] = '\0'; - _len += strlcpy(out_lbl + _len, actual_string, str_len - _len); + _len += strlcpy(out_lbl + _len, actual_string, sizeof(out_lbl) - _len); out_lbl[ _len] = '|'; out_lbl[++_len] = '\0'; - strlcpy(out_lbl + _len, path, str_len - _len); - + strlcpy(out_lbl + _len, path, sizeof(out_lbl) - _len); _len = strlcpy(tmp, desc, sizeof(tmp)); tmp[ _len] = ':'; tmp[++_len] = ' '; @@ -2679,9 +2665,6 @@ static int create_string_list_rdb_entry_string( menu_entries_append(list, tmp, out_lbl, enum_idx, 0, 0, 0, NULL); - - free(out_lbl); - return 0; } @@ -2697,10 +2680,7 @@ static int create_string_list_rdb_entry_int( char tmp[128]; char out_lbl[NAME_MAX_LENGTH]; str[0] = '\0'; - out_lbl[0] = '\0'; - snprintf(str, sizeof(str), "%d", actual_int); - _len = strlcpy(out_lbl, label, sizeof(out_lbl)); out_lbl[ _len] = '|'; out_lbl[++_len] = '\0'; @@ -2708,7 +2688,6 @@ static int create_string_list_rdb_entry_int( out_lbl[ _len] = '|'; out_lbl[++_len] = '\0'; strlcpy(out_lbl + _len, path, sizeof(out_lbl) - _len); - _len = strlcpy(tmp, desc, sizeof(tmp)); tmp[ _len] = ':'; tmp[++_len] = ' '; @@ -2717,7 +2696,6 @@ static int create_string_list_rdb_entry_int( menu_entries_append(list, tmp, out_lbl, enum_idx, 0, 0, 0, NULL); - return 0; } @@ -4717,19 +4695,16 @@ static unsigned menu_displaylist_parse_cores( for (i = 0; i < list_size; i++) { - const char *path = info->list->list[i].path; - unsigned type = info->list->list[i].type; + const char *path = info->list->list[i].path; + unsigned type = info->list->list[i].type; if (type == FILE_TYPE_CORE) { char core_path[PATH_MAX_LENGTH]; char display_name[NAME_MAX_LENGTH]; - display_name[0] = '\0'; - 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))) + core_path, display_name, sizeof(display_name)) > 0) file_list_set_alt_at_offset(info->list, i, display_name); } } @@ -5271,10 +5246,10 @@ static unsigned menu_displaylist_parse_content_information( } /* Runtime */ - if (((settings->uints.playlist_sublabel_runtime_type == PLAYLIST_RUNTIME_PER_CORE) && - settings->bools.content_runtime_log) || - ((settings->uints.playlist_sublabel_runtime_type == PLAYLIST_RUNTIME_AGGREGATE) && - !settings->bools.content_runtime_log_aggregate)) + if ( ((settings->uints.playlist_sublabel_runtime_type == PLAYLIST_RUNTIME_PER_CORE) + && settings->bools.content_runtime_log) + || ((settings->uints.playlist_sublabel_runtime_type == PLAYLIST_RUNTIME_AGGREGATE) + && !settings->bools.content_runtime_log_aggregate)) { runtime_log_t *runtime_log = runtime_log_init( content_path, @@ -5311,7 +5286,6 @@ static unsigned menu_displaylist_parse_content_information( 0, 0, 0, NULL)) count++; } - free(runtime_log); } } @@ -5710,7 +5684,7 @@ static int menu_displaylist_parse_input_select_reserved_device_list( strlcpy(reserved_device_name, settings->arrays.input_reserved_devices[enum_idx - MENU_ENUM_LABEL_INPUT_DEVICE_RESERVED_DEVICE_NAME], sizeof(reserved_device_name)); /* List elements: none/disabled, all existing reservations, all existing devices */ - for (i = MAX_INPUT_DEVICES+MAX_USERS; i >= 0; --i) + for (i = MAX_INPUT_DEVICES + MAX_USERS; i >= 0; --i) { device_label[0] = '\0'; @@ -6614,8 +6588,6 @@ static unsigned menu_displaylist_populate_subsystem( { char star_char[16]; unsigned count = 0; - const char *menu_driver = menu_driver_ident(); - bool menu_show_sublabels = settings->bools.menu_show_sublabels; /* Note: Create this string here explicitly (rather than * using a #define elsewhere) since we need to be aware of * its length... */ @@ -6628,7 +6600,10 @@ static unsigned menu_displaylist_populate_subsystem( static const char utf8_star_char[] = "\xE2\x98\x85"; #endif int i = 0; - bool is_rgui = string_is_equal(menu_driver, "rgui"); +#if defined(HAVE_RGUI) + bool menu_show_sublabels = settings->bools.menu_show_sublabels; + const char *menu_driver = menu_driver_ident(); + bool is_rgui = string_is_equal(menu_driver, "rgui"); /* Select appropriate 'star' marker for subsystem menu entries * (i.e. RGUI does not support unicode, so use a 'standard' @@ -6639,6 +6614,7 @@ static unsigned menu_displaylist_populate_subsystem( star_char[1] = '\0'; } else +#endif strlcpy(star_char, utf8_star_char, sizeof(star_char)); if (menu_displaylist_has_subsystems()) @@ -6697,6 +6673,7 @@ static unsigned menu_displaylist_populate_subsystem( s[++_len] = '\0'; _len += strlcpy(s + _len, star_char, sizeof(s) - _len); +#ifdef HAVE_RGUI /* If using RGUI with sublabels disabled, add the * appropriate text to the menu entry itself... */ if (is_rgui && !menu_show_sublabels) @@ -6721,6 +6698,7 @@ static unsigned menu_displaylist_populate_subsystem( strlcpy(s + _len, "]", sizeof(s) - _len); } } +#endif if (menu_entries_append(list, s, @@ -6738,6 +6716,7 @@ static unsigned menu_displaylist_populate_subsystem( s[++_len] = '\0'; _len += strlcpy(s + _len, subsystem->desc, sizeof(s) - _len); +#ifdef HAVE_RGUI /* If using RGUI with sublabels disabled, add the * appropriate text to the menu entry itself... */ if (is_rgui && !menu_show_sublabels) @@ -6756,6 +6735,7 @@ static unsigned menu_displaylist_populate_subsystem( strlcpy(s + _len, "]", sizeof(s) - _len); } } +#endif if (menu_entries_append(list, s, @@ -6774,9 +6754,7 @@ static unsigned menu_displaylist_populate_subsystem( static unsigned menu_displaylist_netplay_refresh_rooms(file_list_t *list) { int i, j; - char buf[256]; - char passworded[64]; - char country[8]; + char s[256]; const char *room_type; const char *cnc_netplay_room = NULL; const char *msg_int_nc = NULL; @@ -6863,7 +6841,7 @@ static unsigned menu_displaylist_netplay_refresh_rooms(file_list_t *list) for (i = 0; i < net_st->room_count; i++) { - size_t _len; + size_t _len = 0; struct netplay_room *room = &net_st->room_list[i]; /* Get rid of any room that is not running RetroArch. */ @@ -6910,34 +6888,23 @@ static unsigned menu_displaylist_netplay_refresh_rooms(file_list_t *list) { if (!show_passworded) continue; - _len = strlcpy(passworded, "[", - sizeof(passworded)); - _len += strlcpy(passworded + _len, - msg_room_pwd, - sizeof(passworded) - _len); - strlcpy(passworded + _len, "] ", - sizeof(passworded) - _len); + _len += strlcpy(s, "[", sizeof(s) - _len); + _len += strlcpy(s + _len, msg_room_pwd, sizeof(s) - _len); + _len += strlcpy(s + _len, "] ", sizeof(s) - _len); } - else - *passworded = '\0'; - _len = strlcpy(buf, passworded, sizeof(buf)); - _len += strlcpy(buf + _len, room_type, sizeof(buf) - _len); - _len += strlcpy(buf + _len, ": ", sizeof(buf) - _len); - _len += strlcpy(buf + _len, room->nickname, sizeof(buf) - _len); + _len += strlcpy(s + _len, room_type, sizeof(s) - _len); + _len += strlcpy(s + _len, ": ", sizeof(s) - _len); + _len += strlcpy(s + _len, room->nickname, sizeof(s) - _len); if (!room->lan && !string_is_empty(room->country)) { - size_t _len2 = strlcpy(country, " (", sizeof(country)); - _len2 += strlcpy(country + _len2, room->country, sizeof(country) - _len2); - strlcpy(country + _len2, ")", sizeof(country) - _len2); - strlcpy(buf + _len, country, sizeof(buf) - _len); + _len += strlcpy(s + _len, " (", sizeof(s) - _len); + _len += strlcpy(s + _len, room->country, sizeof(s) - _len); + _len += strlcpy(s + _len, ")", sizeof(s) - _len); } - else - *country = '\0'; - if (menu_entries_append(list, buf, - cnc_netplay_room, + if (menu_entries_append(list, s, cnc_netplay_room, MENU_ENUM_LABEL_CONNECT_NETPLAY_ROOM, (unsigned)MENU_SETTINGS_NETPLAY_ROOMS_START + i, 0, 0, NULL)) count++; @@ -8416,7 +8383,6 @@ unsigned menu_displaylist_build_list( for (i = 0; i < num_cheats; i++) { const char *cheat_description = cheat_manager_get_desc(i); - snprintf(cheat_label + _len, sizeof(cheat_label) - _len, " #%u: ", i); if (!string_is_empty(cheat_description)) strlcat(cheat_label, cheat_description, sizeof(cheat_label)); @@ -12314,7 +12280,9 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, { unsigned max_users = settings->uints.input_max_users; const char *menu_driver = menu_driver_ident(); +#ifdef HAVE_RGUI bool is_rgui = string_is_equal(menu_driver, "rgui"); +#endif file_list_t *list = info->list; unsigned port = string_to_unsigned(info->path); unsigned mapped_port = settings->uints.input_remap_ports[port]; @@ -12383,16 +12351,22 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, desc_len = strlcpy(descriptor, desc_lbl, sizeof(descriptor)); } +#ifdef HAVE_RGUI /* Add user index when display driver == rgui and sublabels * are disabled, but only if there is more than one user */ - if ( (is_rgui) - && (max_users > 1) + if ( + (is_rgui) && + (max_users > 1) && !settings->bools.menu_show_sublabels) { - desc_len += strlcpy(descriptor + desc_len, " [", sizeof(descriptor) - desc_len); - snprintf(descriptor + desc_len, sizeof(descriptor) - desc_len, "%s %u]", - msg_val_port, port + 1); + desc_len += strlcpy(descriptor + desc_len, + " [", sizeof(descriptor) - desc_len); + desc_len += strlcpy(descriptor + desc_len, + msg_val_port, sizeof(descriptor) - desc_len); + snprintf(descriptor + desc_len, + sizeof(descriptor) - desc_len," %u]", port + 1); } +#endif /* Note: 'physical' port is passed as label */ if (menu_entries_append(list, descriptor, info->path, @@ -12436,6 +12410,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, desc_len = strlcpy(descriptor, desc_lbl, sizeof(descriptor)); } +#ifdef HAVE_RGUI /* Add user index when display driver == rgui and sublabels * are disabled, but only if there is more than one user */ if ( (is_rgui) @@ -12446,6 +12421,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, snprintf(descriptor + desc_len, sizeof(descriptor) - desc_len, "%s %u]", val_port, port + 1); } +#endif /* Note: 'physical' port is passed as label */ if (menu_entries_append(list, descriptor, info->path, @@ -12885,10 +12861,12 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, for (i = 0; i < profiles_count; i++) { char title[NAME_MAX_LENGTH]; - char* profile = SWITCH_CPU_PROFILES[i]; - char* speed = SWITCH_CPU_SPEEDS[i]; - size_t _len = strlcpy(title, profile, sizeof(title)); - snprintf(title + _len, sizeof(title) - _len, " (%s)", speed); + size_t _len = strlcpy(title, SWITCH_CPU_PROFILES[i], + sizeof(title)); + _len += strlcpy(title + _len, " (", sizeof(title) - _len); + _len += strlcpy(title + _len, SWITCH_CPU_SPEEDS[i], + sizeof(title) - _len); + _len += strlcpy(title + _len, ")", sizeof(title) - _len); if (menu_entries_append(info->list, title, "", 0, MENU_SET_SWITCH_CPU_PROFILE, 0, i, NULL)) count++; diff --git a/retroarch.c b/retroarch.c index a1160b0cdb..6c71949622 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1128,161 +1128,90 @@ size_t midi_driver_get_event_size(uint8_t status) * Returns: NULL if no driver based on @label found, otherwise * pointer to driver. **/ -static const void *find_driver_nonempty( - const char *label, int i, - char *s, size_t len) +static size_t find_driver_nonempty( + const char *label, int i, char *s, size_t len) { if (string_is_equal(label, "camera_driver")) { if (camera_drivers[i]) - { - const char *ident = camera_drivers[i]->ident; - - strlcpy(s, ident, len); - return camera_drivers[i]; - } + return strlcpy(s, camera_drivers[i]->ident, len); } else if (string_is_equal(label, "location_driver")) { if (location_drivers[i]) - { - const char *ident = location_drivers[i]->ident; - - strlcpy(s, ident, len); - return location_drivers[i]; - } + return strlcpy(s, location_drivers[i]->ident, len); } #ifdef HAVE_MENU else if (string_is_equal(label, "menu_driver")) { if (menu_ctx_drivers[i]) - { - const char *ident = menu_ctx_drivers[i]->ident; - - strlcpy(s, ident, len); - return menu_ctx_drivers[i]; - } + return strlcpy(s, menu_ctx_drivers[i]->ident, len); } #endif else if (string_is_equal(label, "input_driver")) { if (input_drivers[i]) - { - const char *ident = input_drivers[i]->ident; - - strlcpy(s, ident, len); - return input_drivers[i]; - } + return strlcpy(s, input_drivers[i]->ident, len); } else if (string_is_equal(label, "input_joypad_driver")) { if (joypad_drivers[i]) - { - const char *ident = joypad_drivers[i]->ident; - - strlcpy(s, ident, len); - return joypad_drivers[i]; - } + return strlcpy(s, joypad_drivers[i]->ident, len); } else if (string_is_equal(label, "video_driver")) { if (video_drivers[i]) - { - const char *ident = video_drivers[i]->ident; - - strlcpy(s, ident, len); - return video_drivers[i]; - } + return strlcpy(s, video_drivers[i]->ident, len); } else if (string_is_equal(label, "audio_driver")) { if (audio_drivers[i]) - { - const char *ident = audio_drivers[i]->ident; - - strlcpy(s, ident, len); - return audio_drivers[i]; - } + return strlcpy(s, audio_drivers[i]->ident, len); } #ifdef HAVE_MICROPHONE else if (string_is_equal(label, "microphone_driver")) { if (microphone_drivers[i]) - { - const char *ident = microphone_drivers[i]->ident; - - strlcpy(s, ident, len); - return microphone_drivers[i]; - } + return strlcpy(s, microphone_drivers[i]->ident, len); } #endif else if (string_is_equal(label, "record_driver")) { if (record_drivers[i]) - { - const char *ident = record_drivers[i]->ident; - - strlcpy(s, ident, len); - return record_drivers[i]; - } + return strlcpy(s, record_drivers[i]->ident, len); } else if (string_is_equal(label, "midi_driver")) { if (midi_driver_find_handle(i)) - { - const char *ident = midi_drivers[i]->ident; - - strlcpy(s, ident, len); - return midi_drivers[i]; - } + return strlcpy(s, midi_drivers[i]->ident, len); } else if (string_is_equal(label, "audio_resampler_driver")) { if (audio_resampler_driver_find_handle(i)) - { - const char *ident = audio_resampler_driver_find_ident(i); - - strlcpy(s, ident, len); - return audio_resampler_driver_find_handle(i); - } + return strlcpy(s, audio_resampler_driver_find_ident(i), len); } #ifdef HAVE_BLUETOOTH else if (string_is_equal(label, "bluetooth_driver")) { if (bluetooth_drivers[i]) - { - const char *ident = bluetooth_drivers[i]->ident; - - strlcpy(s, ident, len); - return bluetooth_drivers[i]; - } + return strlcpy(s, bluetooth_drivers[i]->ident, len); } #endif #ifdef HAVE_WIFI else if (string_is_equal(label, "wifi_driver")) { if (wifi_drivers[i]) - { - const char *ident = wifi_drivers[i]->ident; - - strlcpy(s, ident, len); - return wifi_drivers[i]; - } + return strlcpy(s, wifi_drivers[i]->ident, len); } #endif #ifdef HAVE_CLOUDSYNC else if (string_is_equal(label, "cloud_sync_driver")) { if (cloud_sync_drivers[i]) - { - const char *ident = cloud_sync_drivers[i]->ident; - - strlcpy(s, ident, len); - return cloud_sync_drivers[i]; - } + return strlcpy(s, cloud_sync_drivers[i]->ident, len); } #endif - return NULL; + return 0; } int driver_find_index(const char *label, const char *drv) @@ -1293,7 +1222,7 @@ int driver_find_index(const char *label, const char *drv) str[0] = '\0'; for (i = 0; - find_driver_nonempty(label, i, str, sizeof(str)) != NULL; i++) + find_driver_nonempty(label, i, str, sizeof(str)) > 0; i++) { if (string_is_empty(str)) break; @@ -1317,7 +1246,7 @@ static void driver_find_last(const char *label, char *s, size_t len) unsigned i; for (i = 0; - find_driver_nonempty(label, i, s, len) != NULL; i++) { } + find_driver_nonempty(label, i, s, len) > 0; i++) { } if (i) i = i - 1; @@ -8259,8 +8188,8 @@ bool retroarch_override_setting_is_set( return false; } -int retroarch_get_capabilities(enum rarch_capabilities type, - char *str_out, size_t str_len) +size_t retroarch_get_capabilities(enum rarch_capabilities type, + char *s, size_t len) { size_t _len = 0; switch (type) @@ -8269,80 +8198,79 @@ int retroarch_get_capabilities(enum rarch_capabilities type, { uint64_t cpu = cpu_features_get(); if (cpu & RETRO_SIMD_MMX) - _len += strlcpy(str_out + _len, "MMX ", str_len - _len); + _len += strlcpy(s + _len, "MMX ", len - _len); if (cpu & RETRO_SIMD_MMXEXT) - _len += strlcpy(str_out + _len, "MMXEXT ", str_len - _len); + _len += strlcpy(s + _len, "MMXEXT ", len - _len); if (cpu & RETRO_SIMD_SSE) - _len += strlcpy(str_out + _len, "SSE ", str_len - _len); + _len += strlcpy(s + _len, "SSE ", len - _len); if (cpu & RETRO_SIMD_SSE2) - _len += strlcpy(str_out + _len, "SSE2 ", str_len - _len); + _len += strlcpy(s + _len, "SSE2 ", len - _len); if (cpu & RETRO_SIMD_SSE3) - _len += strlcpy(str_out + _len, "SSE3 ", str_len - _len); + _len += strlcpy(s + _len, "SSE3 ", len - _len); if (cpu & RETRO_SIMD_SSSE3) - _len += strlcpy(str_out + _len, "SSSE3 ", str_len - _len); + _len += strlcpy(s + _len, "SSSE3 ", len - _len); if (cpu & RETRO_SIMD_SSE4) - _len += strlcpy(str_out + _len, "SSE4 ", str_len - _len); + _len += strlcpy(s + _len, "SSE4 ", len - _len); if (cpu & RETRO_SIMD_SSE42) - _len += strlcpy(str_out + _len, "SSE42 ", str_len - _len); + _len += strlcpy(s + _len, "SSE42 ", len - _len); if (cpu & RETRO_SIMD_AES) - _len += strlcpy(str_out + _len, "AES ", str_len - _len); + _len += strlcpy(s + _len, "AES ", len - _len); if (cpu & RETRO_SIMD_AVX) - _len += strlcpy(str_out + _len, "AVX ", str_len - _len); + _len += strlcpy(s + _len, "AVX ", len - _len); if (cpu & RETRO_SIMD_AVX2) - _len += strlcpy(str_out + _len, "AVX2 ", str_len - _len); + _len += strlcpy(s + _len, "AVX2 ", len - _len); if (cpu & RETRO_SIMD_NEON) - _len += strlcpy(str_out + _len, "NEON ", str_len - _len); + _len += strlcpy(s + _len, "NEON ", len - _len); if (cpu & RETRO_SIMD_VFPV3) - _len += strlcpy(str_out + _len, "VFPV3 ", str_len - _len); + _len += strlcpy(s + _len, "VFPV3 ", len - _len); if (cpu & RETRO_SIMD_VFPV4) - _len += strlcpy(str_out + _len, "VFPV4 ", str_len - _len); + _len += strlcpy(s + _len, "VFPV4 ", len - _len); if (cpu & RETRO_SIMD_VMX) - _len += strlcpy(str_out + _len, "VMX ", str_len - _len); + _len += strlcpy(s + _len, "VMX ", len - _len); if (cpu & RETRO_SIMD_VMX128) - _len += strlcpy(str_out + _len, "VMX128 ", str_len - _len); + _len += strlcpy(s + _len, "VMX128 ", len - _len); if (cpu & RETRO_SIMD_VFPU) - _len += strlcpy(str_out + _len, "VFPU ", str_len - _len); + _len += strlcpy(s + _len, "VFPU ", len - _len); if (cpu & RETRO_SIMD_PS) - _len += strlcpy(str_out + _len, "PS ", str_len - _len); + _len += strlcpy(s + _len, "PS ", len - _len); if (cpu & RETRO_SIMD_ASIMD) - _len += strlcpy(str_out + _len, "ASIMD ", str_len - _len); + _len += strlcpy(s + _len, "ASIMD ", len - _len); break; } break; case RARCH_CAPABILITIES_COMPILER: #if defined(_MSC_VER) - _len = strlcpy(str_out, msg_hash_to_str(MSG_COMPILER), str_len); - _len += snprintf(str_out + _len, str_len - _len, ": MSVC (%d)", + _len += strlcpy (s + _len, msg_hash_to_str(MSG_COMPILER), len - _len); + _len += snprintf(s + _len, len - _len, ": MSVC (%d)", _MSC_VER); #elif defined(__SNC__) - _len = strlcpy(str_out, msg_hash_to_str(MSG_COMPILER), str_len); - _len += snprintf(str_out + _len, str_len - _len, ": SNC (%d)", + _len += strlcpy (s + _len, msg_hash_to_str(MSG_COMPILER), len - _len); + _len += snprintf(s + _len, len - _len, ": SNC (%d)", __SN_VER__); #elif defined(_WIN32) && defined(__GNUC__) - _len = strlcpy(str_out, msg_hash_to_str(MSG_COMPILER), str_len); - _len += snprintf(str_out + _len, str_len - _len, ": MinGW (%d.%d.%d)", + _len += strlcpy (s + _len, msg_hash_to_str(MSG_COMPILER), len - _len); + _len += snprintf(s + _len, len - _len, ": MinGW (%d.%d.%d)", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); #elif defined(__clang__) - _len = strlcpy(str_out, msg_hash_to_str(MSG_COMPILER), str_len); - _len += strlcpy(str_out + _len, ": Clang/LLVM (", str_len - _len); - _len += strlcpy(str_out + _len, __clang_version__, str_len - _len); - _len += strlcpy(str_out + _len, ")", str_len - _len); + _len += strlcpy(s + _len, msg_hash_to_str(MSG_COMPILER), len - _len); + _len += strlcpy(s + _len, ": Clang/LLVM (", len - _len); + _len += strlcpy(s + _len, __clang_version__, len - _len); + _len += strlcpy(s + _len, ")", len - _len); #elif defined(__GNUC__) - _len = strlcpy(str_out, msg_hash_to_str(MSG_COMPILER), str_len); - _len += snprintf(str_out + _len, str_len - _len, ": GCC (%d.%d.%d)", + _len += strlcpy (s + _len, msg_hash_to_str(MSG_COMPILER), len - _len); + _len += snprintf(s + _len, len - _len, ": GCC (%d.%d.%d)", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); #else - _len = strlcpy(str_out, msg_hash_to_str(MSG_UNKNOWN_COMPILER), str_len); + _len += strlcpy(s + _len, msg_hash_to_str(MSG_UNKNOWN_COMPILER), len - _len); #endif - snprintf(str_out + _len, str_len - _len, " %u-bit", + _len += snprintf(s + _len, len - _len, " %u-bit", (unsigned)(CHAR_BIT * sizeof(size_t))); break; default: case RARCH_CAPABILITIES_NONE: break; } - - return 0; + return _len; } void retroarch_fail(int error_code, const char *error) diff --git a/retroarch.h b/retroarch.h index b57e0d3f6d..40627a094f 100644 --- a/retroarch.h +++ b/retroarch.h @@ -112,7 +112,7 @@ enum rarch_state_flags bool retroarch_ctl(enum rarch_ctl_state state, void *data); -int retroarch_get_capabilities(enum rarch_capabilities type, +size_t retroarch_get_capabilities(enum rarch_capabilities type, char *s, size_t len); void retroarch_override_setting_set(enum rarch_override_setting enum_idx, void *data); diff --git a/runloop.c b/runloop.c index 62c6487629..037169cf32 100644 --- a/runloop.c +++ b/runloop.c @@ -1266,7 +1266,6 @@ static void runloop_init_core_options_path( if (per_core_options) { strlcpy(s, per_core_options_path, len); - if (!per_core_options_exist) strlcpy(src_path, global_options_path, src_len); } @@ -1957,8 +1956,7 @@ bool runloop_environment_cb(unsigned cmd, void *data) RARCH_WARN("[Environ]: SYSTEM DIR is empty, assume CONTENT DIR %s\n", fullpath); - strlcpy(tmp_path, fullpath, sizeof(tmp_path)); - path_basedir(tmp_path); + fill_pathname_basedir(tmp_path, fullpath, sizeof(tmp_path)); /* Removes trailing slash (unless root dir) */ len = strlen(tmp_path); @@ -7903,7 +7901,8 @@ void runloop_path_set_redirect(settings_t *settings, sizeof(content_dir_name)); /* Set savefile directory if empty to content directory */ - if (string_is_empty(intermediate_savefile_dir) || savefiles_in_content_dir) + if ( string_is_empty(intermediate_savefile_dir) + || savefiles_in_content_dir) { strlcpy(intermediate_savefile_dir, runloop_st->runtime_content_path_basename, @@ -7915,7 +7914,7 @@ void runloop_path_set_redirect(settings_t *settings, } /* Set savestate directory if empty based on content directory */ - if (string_is_empty(intermediate_savestate_dir) + if ( string_is_empty(intermediate_savestate_dir) || savestates_in_content_dir) { strlcpy(intermediate_savestate_dir, @@ -8013,11 +8012,12 @@ void runloop_path_set_redirect(settings_t *settings, && !netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_SERVER, NULL) && !netplay_driver_ctl(RARCH_NETPLAY_CTL_USE_CORE_PACKET_INTERFACE, NULL)) { - fill_pathname_join(new_savefile_dir, new_savefile_dir, ".netplay", - sizeof(new_savefile_dir)); + fill_pathname_join(new_savefile_dir, + new_savefile_dir, ".netplay", + sizeof(new_savefile_dir)); - if (!path_is_directory(new_savefile_dir) && - !path_mkdir(new_savefile_dir)) + if ( !path_is_directory(new_savefile_dir) + && !path_mkdir(new_savefile_dir)) path_basedir(new_savefile_dir); } #endif @@ -8038,7 +8038,8 @@ void runloop_path_set_redirect(settings_t *settings, sizeof(runloop_st->name.savestate)); strlcpy(runloop_st->name.replay, new_savestate_dir, sizeof(runloop_st->name.replay)); - } else + } + else savestate_is_dir = path_is_directory(runloop_st->name.savestate); if (savefile_is_dir)