Reduce amount of strlcats in retroarch.c

This commit is contained in:
LibretroAdmin 2022-08-08 21:46:37 +02:00
parent c030e1c5dc
commit 05cf639712
2 changed files with 189 additions and 152 deletions

View File

@ -4119,24 +4119,29 @@ static void retroarch_print_help(const char *arg0)
fprintf(stdout, "Usage: %s [OPTIONS]... [FILE]\n\n", arg0); fprintf(stdout, "Usage: %s [OPTIONS]... [FILE]\n\n", arg0);
strlcat(buf, " -h, --help " strlcat(buf,
"Show this help message.\n", sizeof(buf)); " -h, --help "
strlcat(buf, " -v, --verbose " "Show this help message.\n"
"Verbose logging.\n", sizeof(buf)); " -v, --verbose "
strlcat(buf, " --log-file=FILE " "Verbose logging.\n"
"Log messages to FILE.\n", sizeof(buf)); " --log-file=FILE "
strlcat(buf, " --version " "Log messages to FILE.\n"
"Show version.\n", sizeof(buf)); " --version "
strlcat(buf, " --features " "Show version.\n"
"Print available features compiled into program.\n", sizeof(buf)); " --features "
"Print available features compiled into program.\n"
,
sizeof(buf));
#ifdef HAVE_MENU #ifdef HAVE_MENU
strlcat(buf, " --menu " strlcat(buf,
"Do not require content or libretro core to be loaded,\n", sizeof(buf)); " --menu "
strlcat(buf, " " "Do not require content or libretro core to be loaded,\n"
" starts directly in menu. If no arguments are passed to\n", sizeof(buf)); " "
strlcat(buf, " " " starts directly in menu. If no arguments are passed to\n"
" the program, it is equivalent to using --menu as only argument.\n", sizeof(buf)); " "
" the program, it is equivalent to using --menu as only argument.\n"
,
sizeof(buf));
#endif #endif
#ifdef HAVE_CONFIGFILE #ifdef HAVE_CONFIGFILE
@ -4144,72 +4149,79 @@ static void retroarch_print_help(const char *arg0)
"Path for config file.\n", sizeof(buf)); "Path for config file.\n", sizeof(buf));
#ifdef _WIN32 #ifdef _WIN32
strlcat(buf, " " strlcat(buf, " "
" Defaults to retroarch.cfg in same directory as retroarch.exe.\n", sizeof(buf)); " Defaults to retroarch.cfg in same directory as retroarch.exe.\n"
strlcat(buf, " " " "
" If a default config is not found, the program will attempt to create one.\n", sizeof(buf)); " If a default config is not found, the program will attempt to create one.\n"
, sizeof(buf));
#else #else
strlcat(buf, " " strlcat(buf,
" By default looks for config in\n", sizeof(buf)); " "
strlcat(buf, " " " By default looks for config in\n"
" $XDG_CONFIG_HOME/retroarch/retroarch.cfg,\n", sizeof(buf)); " "
strlcat(buf, " " " $XDG_CONFIG_HOME/retroarch/retroarch.cfg,\n"
" $HOME/.config/retroarch/retroarch.cfg, and\n", sizeof(buf)); " "
strlcat(buf, " " " $HOME/.config/retroarch/retroarch.cfg, and\n"
" $HOME/.retroarch.cfg.\n", sizeof(buf)); " "
strlcat(buf, " " " $HOME/.retroarch.cfg.\n"
" If a default config is not found, the program will attempt to create one\n", sizeof(buf)); " "
strlcat(buf, " " " If a default config is not found, the program will attempt to create one\n"
" based on the skeleton config (" GLOBAL_CONFIG_DIR "/retroarch.cfg).\n", sizeof(buf)); " "
" based on the skeleton config (" GLOBAL_CONFIG_DIR "/retroarch.cfg).\n"
, sizeof(buf));
#endif #endif
strlcat(buf, " --appendconfig=FILE " strlcat(buf, " --appendconfig=FILE "
"Extra config files are loaded in, and take priority over\n", sizeof(buf)); "Extra config files are loaded in, and take priority over\n"
strlcat(buf, " " " "
" config selected in -c (or default). Multiple configs are\n", sizeof(buf)); " config selected in -c (or default). Multiple configs are\n"
strlcat(buf, " " " "
" delimited by '|'.\n", sizeof(buf)); " delimited by '|'.\n"
, sizeof(buf));
#endif #endif
fputs(buf, stdout); fputs(buf, stdout);
buf[0] = '\0'; buf[0] = '\0';
#ifdef HAVE_DYNAMIC #ifdef HAVE_DYNAMIC
strlcat(buf, " -L, --libretro=FILE " strlcat(buf,
"Path to libretro implementation. Overrides any config setting.\n", sizeof(buf)); " -L, --libretro=FILE "
strlcat(buf, " " "Path to libretro implementation. Overrides any config setting.\n"
" FILE may be one of the following:\n", sizeof(buf)); " "
strlcat(buf, " " " FILE may be one of the following:\n"
" 1. The full path to a core shared object library: path/to/<core_name>_libretro.<lib_ext>\n", sizeof(buf)); " "
strlcat(buf, " " " 1. The full path to a core shared object library: path/to/<core_name>_libretro.<lib_ext>\n"
" 2. A core shared object library 'file name' (*): <core_name>_libretro.<lib_ext>\n", sizeof(buf)); " "
strlcat(buf, " " " 2. A core shared object library 'file name' (*): <core_name>_libretro.<lib_ext>\n"
" 3. A core 'short name' (*): <core_name>_libretro OR <core_name>\n", sizeof(buf)); " "
strlcat(buf, " " " 3. A core 'short name' (*): <core_name>_libretro OR <core_name>\n"
" (*) If 'file name' or 'short name' do not correspond to an existing full file path,\n", sizeof(buf)); " "
strlcat(buf, " " " (*) If 'file name' or 'short name' do not correspond to an existing full file path,\n"
" the configured frontend 'cores' directory will be searched for a match.\n", sizeof(buf)); " "
" the configured frontend 'cores' directory will be searched for a match.\n"
, sizeof(buf));
#endif #endif
strlcat(buf, " --subsystem=NAME " strlcat(buf,
"Use a subsystem of the libretro core. Multiple content\n", sizeof(buf)); " --subsystem=NAME "
strlcat(buf, " " "Use a subsystem of the libretro core. Multiple content\n"
" files are loaded as multiple arguments. If a content\n", sizeof(buf)); " "
strlcat(buf, " " " files are loaded as multiple arguments. If a content\n"
" file is skipped, use a blank (\"\") command line argument.\n", sizeof(buf)); " "
strlcat(buf, " " " file is skipped, use a blank (\"\") command line argument.\n"
" Content must be loaded in an order which depends on the\n", sizeof(buf)); " "
strlcat(buf, " " " Content must be loaded in an order which depends on the\n"
" particular subsystem used. See verbose log output to learn\n", sizeof(buf)); " "
strlcat(buf, " " " particular subsystem used. See verbose log output to learn\n"
" how a particular subsystem wants content to be loaded.\n", sizeof(buf)); " "
" how a particular subsystem wants content to be loaded.\n"
strlcat(buf, " -f, --fullscreen " " -f, --fullscreen "
"Start the program in fullscreen regardless of config setting.\n", sizeof(buf)); "Start the program in fullscreen regardless of config setting.\n"
strlcat(buf, " --set-shader=PATH " " --set-shader=PATH "
"Path to a shader (preset) that will be loaded each time content is loaded.\n", sizeof(buf)); "Path to a shader (preset) that will be loaded each time content is loaded.\n"
strlcat(buf, " " " "
" Effectively overrides automatic shader presets.\n", sizeof(buf)); " Effectively overrides automatic shader presets.\n"
strlcat(buf, " " " "
" An empty argument \"\" will disable automatic shader presets.\n", sizeof(buf)); " An empty argument \"\" will disable automatic shader presets.\n"
, sizeof(buf));
fputs(buf, stdout); fputs(buf, stdout);
buf[0] = '\0'; buf[0] = '\0';
@ -4220,77 +4232,88 @@ static void retroarch_print_help(const char *arg0)
"Connect a DualAnalog controller to PORT (1 to %d).\n", MAX_USERS); "Connect a DualAnalog controller to PORT (1 to %d).\n", MAX_USERS);
printf( " -d, --device=PORT:ID " printf( " -d, --device=PORT:ID "
"Connect a generic device into PORT of the device (1 to %d).\n", MAX_USERS); "Connect a generic device into PORT of the device (1 to %d).\n", MAX_USERS);
strlcat(buf, " " strlcat(buf,
" Format is PORT:ID, where ID is a number corresponding to the particular device.\n", sizeof(buf)); " "
" Format is PORT:ID, where ID is a number corresponding to the particular device.\n"
strlcat(buf, " -M, --sram-mode=MODE " " -M, --sram-mode=MODE "
"SRAM handling mode. MODE can be:\n", sizeof(buf)); "SRAM handling mode. MODE can be:\n"
strlcat(buf, " " " "
" 'noload-nosave', 'noload-save', 'load-nosave' or 'load-save'.\n", sizeof(buf)); " 'noload-nosave', 'noload-save', 'load-nosave' or 'load-save'.\n"
strlcat(buf, " " " "
" Note: 'noload-save' implies that save files *WILL BE OVERWRITTEN*.\n", sizeof(buf)); " Note: 'noload-save' implies that save files *WILL BE OVERWRITTEN*.\n"
, sizeof(buf));
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
strlcat(buf, " -H, --host " strlcat(buf,
"Host netplay as user 1.\n", sizeof(buf)); " -H, --host "
strlcat(buf, " -C, --connect=HOST " "Host netplay as user 1.\n"
"Connect to netplay server as user 2.\n", sizeof(buf)); " -C, --connect=HOST "
strlcat(buf, " --port=PORT " "Connect to netplay server as user 2.\n"
"Port used to netplay. Default is 55435.\n", sizeof(buf)); " --port=PORT "
strlcat(buf, " --nick=NICK " "Port used to netplay. Default is 55435.\n"
"Picks a username (for use with netplay). Not mandatory.\n", sizeof(buf)); " --nick=NICK "
/*strlcat(buf, " --stateless " "Picks a username (for use with netplay). Not mandatory.\n"
"Use \"stateless\" mode for netplay (requires a very fast network).\n", sizeof(buf));*/ " --check-frames=NUMBER "
strlcat(buf, " --check-frames=NUMBER " "Check frames when using netplay.\n"
"Check frames when using netplay.\n", sizeof(buf)); , sizeof(buf));
#ifdef HAVE_NETWORK_CMD #ifdef HAVE_NETWORK_CMD
strlcat(buf, " --command " strlcat(buf, " --command "
"Sends a command over UDP to an already running program process.\n", sizeof(buf)); "Sends a command over UDP to an already running program process.\n"
strlcat(buf, " " " "
" Available commands are listed if command is invalid.\n", sizeof(buf)); " Available commands are listed if command is invalid.\n"
, sizeof(buf));
#endif #endif
#endif #endif
#ifdef HAVE_BSV_MOVIE #ifdef HAVE_BSV_MOVIE
strlcat(buf, " -P, --bsvplay=FILE " strlcat(buf,
"Playback a BSV movie file.\n", sizeof(buf)); " -P, --bsvplay=FILE "
strlcat(buf, " -R, --bsvrecord=FILE " "Playback a BSV movie file.\n"
"Start recording a BSV movie file from the beginning.\n", sizeof(buf)); " -R, --bsvrecord=FILE "
strlcat(buf, " --eof-exit " "Start recording a BSV movie file from the beginning.\n"
"Exit upon reaching the end of the BSV movie file.\n", sizeof(buf)); " --eof-exit "
"Exit upon reaching the end of the BSV movie file.\n"
, sizeof(buf));
#endif #endif
strlcat(buf, " -r, --record=FILE " strlcat(buf, " -r, --record=FILE "
"Path to record video file. Using mkv extension is recommended.\n", sizeof(buf)); "Path to record video file. Using mkv extension is recommended.\n"
strlcat(buf, " --recordconfig " " --recordconfig "
"Path to settings used during recording.\n", sizeof(buf)); "Path to settings used during recording.\n"
strlcat(buf, " --size=WIDTHxHEIGHT " " --size=WIDTHxHEIGHT "
"Overrides output video size when recording.\n", sizeof(buf)); "Overrides output video size when recording.\n"
,
sizeof(buf));
fputs(buf, stdout); fputs(buf, stdout);
buf[0] = '\0'; buf[0] = '\0';
strlcat(buf, " -D, --detach " strlcat(buf, " -D, --detach "
"Detach program from the running console. Not relevant for all platforms.\n", sizeof(buf)); "Detach program from the running console. Not relevant for all platforms.\n"
strlcat(buf, " --max-frames=NUMBER " " --max-frames=NUMBER "
"Runs for the specified number of frames, then exits.\n", sizeof(buf)); "Runs for the specified number of frames, then exits.\n"
, sizeof(buf));
#ifdef HAVE_PATCH #ifdef HAVE_PATCH
strlcat(buf, " -U, --ups=FILE " strlcat(buf,
"Specifies path for UPS patch that will be applied to content.\n", sizeof(buf)); " -U, --ups=FILE "
strlcat(buf, " --bps=FILE " "Specifies path for UPS patch that will be applied to content.\n"
"Specifies path for BPS patch that will be applied to content.\n", sizeof(buf)); " --bps=FILE "
strlcat(buf, " --ips=FILE " "Specifies path for BPS patch that will be applied to content.\n"
"Specifies path for IPS patch that will be applied to content.\n", sizeof(buf)); " --ips=FILE "
strlcat(buf, " --no-patch " "Specifies path for IPS patch that will be applied to content.\n"
"Disables all forms of content patching.\n", sizeof(buf)); " --no-patch "
"Disables all forms of content patching.\n"
, sizeof(buf));
#endif #endif
#ifdef HAVE_SCREENSHOTS #ifdef HAVE_SCREENSHOTS
strlcat(buf, " --max-frames-ss " strlcat(buf,
"Takes a screenshot at the end of max-frames.\n", sizeof(buf)); " --max-frames-ss "
strlcat(buf, " --max-frames-ss-path=FILE " "Takes a screenshot at the end of max-frames.\n"
"Path to save the screenshot to at the end of max-frames.\n", sizeof(buf)); " --max-frames-ss-path=FILE "
"Path to save the screenshot to at the end of max-frames.\n"
, sizeof(buf));
#endif #endif
#ifdef HAVE_ACCESSIBILITY #ifdef HAVE_ACCESSIBILITY
@ -4298,15 +4321,17 @@ static void retroarch_print_help(const char *arg0)
"Enables accessibilty for blind users using text-to-speech.\n", sizeof(buf)); "Enables accessibilty for blind users using text-to-speech.\n", sizeof(buf));
#endif #endif
strlcat(buf, " --load-menu-on-error " strlcat(buf,
"Open menu instead of quitting if specified core or content fails to load.\n", sizeof(buf)); " --load-menu-on-error "
strlcat(buf, " -e, --entryslot=NUMBER " "Open menu instead of quitting if specified core or content fails to load.\n"
"Slot from which to load an entry state.\n", sizeof(buf)); " -e, --entryslot=NUMBER "
"Slot from which to load an entry state.\n"
strlcat(buf, " -s, --save=PATH " " -s, --save=PATH "
"Path for save files (*.srm). (DEPRECATED, use --appendconfig and savefile_directory)\n", sizeof(buf)); "Path for save files (*.srm). (DEPRECATED, use --appendconfig and savefile_directory)\n"
strlcat(buf, " -S, --savestate=PATH " " -S, --savestate=PATH "
"Path for the save state files (*.state). (DEPRECATED, use --appendconfig and savestate_directory)\n", sizeof(buf)); "Path for the save state files (*.state). (DEPRECATED, use --appendconfig and savestate_directory)\n"
,
sizeof(buf));
fputs(buf, stdout); fputs(buf, stdout);
fputs("\n", stdout); fputs("\n", stdout);
@ -4396,6 +4421,7 @@ static void retroarch_parse_input_libretro_path(const char *path)
} }
else else
{ {
size_t _len;
/* If path has no extension and contains no path /* If path has no extension and contains no path
* delimiters, check if it is a core 'name', matching * delimiters, check if it is a core 'name', matching
* an existing file in the cores directory */ * an existing file in the cores directory */
@ -4404,11 +4430,22 @@ static void retroarch_parse_input_libretro_path(const char *path)
command_event(CMD_EVENT_CORE_INFO_INIT, NULL); command_event(CMD_EVENT_CORE_INFO_INIT, NULL);
strlcpy(tmp_path, path, sizeof(tmp_path)); _len = strlcpy(tmp_path, path, sizeof(tmp_path));
if (!string_ends_with_size(tmp_path, "_libretro", if (!string_ends_with_size(tmp_path, "_libretro",
strlen(tmp_path), STRLEN_CONST("_libretro"))) strlen(tmp_path), STRLEN_CONST("_libretro")))
strlcat(tmp_path, "_libretro", sizeof(tmp_path)); {
tmp_path[_len ] = '_';
tmp_path[_len+1] = 'l';
tmp_path[_len+2] = 'i';
tmp_path[_len+3] = 'b';
tmp_path[_len+4] = 'r';
tmp_path[_len+5] = 'e';
tmp_path[_len+6] = 't';
tmp_path[_len+7] = 'r';
tmp_path[_len+8] = 'o';
tmp_path[_len+9] = '\0';
}
if (!core_info_find(tmp_path, &core_info) || if (!core_info_find(tmp_path, &core_info) ||
string_is_empty(core_info->path)) string_is_empty(core_info->path))
@ -5255,9 +5292,10 @@ bool retroarch_main_init(int argc, char *argv[])
if (!string_is_empty(cpu_model)) if (!string_is_empty(cpu_model))
{ {
strlcat(str_output, FILE_PATH_LOG_INFO " CPU Model Name: ", sizeof(str_output)); size_t _len = strlcat(str_output, FILE_PATH_LOG_INFO " CPU Model Name: ", sizeof(str_output));
strlcat(str_output, cpu_model, sizeof(str_output)); _len = strlcat(str_output, cpu_model, sizeof(str_output));
strlcat(str_output, "\n", sizeof(str_output)); str_output[_len ] = '\n';
str_output[_len+1] = '\0';
} }
RARCH_LOG_OUTPUT("%s", str_output); RARCH_LOG_OUTPUT("%s", str_output);

View File

@ -625,7 +625,8 @@ void runtime_log_get_last_played_time(runtime_log_t *runtime_log,
mktime(time_info); mktime(time_info);
} }
static void last_played_strftime(char *s, size_t len, const char *format, static void runtime_last_played_strftime(
char *s, size_t len, const char *format,
const struct tm *timeptr) const struct tm *timeptr)
{ {
char *local = NULL; char *local = NULL;
@ -636,8 +637,7 @@ static void last_played_strftime(char *s, size_t len, const char *format,
/* Generate string */ /* Generate string */
strftime(s, len, format, timeptr); strftime(s, len, format, timeptr);
#if !(defined(__linux__) && !defined(ANDROID)) #if !(defined(__linux__) && !defined(ANDROID))
local = local_to_utf8_string_alloc(s); if ((local = local_to_utf8_string_alloc(s)))
if (local)
{ {
if (!string_is_empty(local)) if (!string_is_empty(local))
strlcpy(s, local, len); strlcpy(s, local, len);
@ -648,7 +648,7 @@ static void last_played_strftime(char *s, size_t len, const char *format,
#endif #endif
} }
static void last_played_human(runtime_log_t *runtime_log, static bool runtime_last_played_human(runtime_log_t *runtime_log,
char *str, size_t len) char *str, size_t len)
{ {
struct tm time_info; struct tm time_info;
@ -672,23 +672,16 @@ static void last_played_human(runtime_log_t *runtime_log,
float periods[6] = {60.0f, 60.0f, 24.0f, 7.0f, 4.35f, 12.0f}; float periods[6] = {60.0f, 60.0f, 24.0f, 7.0f, 4.35f, 12.0f};
if (!runtime_log) if (!runtime_log)
{ return false;
strlcat(str, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_INLINE_CORE_DISPLAY_NEVER), len);
return;
}
/* Get time */ /* Get time */
runtime_log_get_last_played_time(runtime_log, &time_info); runtime_log_get_last_played_time(runtime_log, &time_info);
last_played = mktime(&time_info); last_played = mktime(&time_info);
current = time(NULL); current = time(NULL);
delta = current - last_played;
if (delta <= 0) if ((delta = current - last_played) <= 0)
{ return false;
strlcat(str, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_INLINE_CORE_DISPLAY_NEVER), len);
return;
}
for (i = 0; delta >= periods[i] && i < sizeof(periods) - 1; i++) for (i = 0; delta >= periods[i] && i < sizeof(periods) - 1; i++)
delta /= periods[i]; delta /= periods[i];
@ -701,6 +694,8 @@ static void last_played_human(runtime_log_t *runtime_log,
strlcat(str, tmp, len); strlcat(str, tmp, len);
strlcat(str, " ", len); strlcat(str, " ", len);
strlcat(str, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_TIME_UNIT_AGO), len); strlcat(str, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_TIME_UNIT_AGO), len);
return true;
} }
/* Gets last played entry value as a pre-formatted string */ /* Gets last played entry value as a pre-formatted string */
@ -857,7 +852,7 @@ void runtime_log_get_last_played_str(runtime_log_t *runtime_log,
/* Get time */ /* Get time */
struct tm time_info; struct tm time_info;
runtime_log_get_last_played_time(runtime_log, &time_info); runtime_log_get_last_played_time(runtime_log, &time_info);
last_played_strftime(tmp, sizeof(tmp), format_str, &time_info); runtime_last_played_strftime(tmp, sizeof(tmp), format_str, &time_info);
} }
snprintf(str, len, "%s%s", snprintf(str, len, "%s%s",
msg_hash_to_str( msg_hash_to_str(
@ -1140,7 +1135,11 @@ void runtime_log_get_last_played_str(runtime_log_t *runtime_log,
runtime_log->last_played.day, runtime_log->last_played.month); runtime_log->last_played.day, runtime_log->last_played.month);
return; return;
case PLAYLIST_LAST_PLAYED_STYLE_AGO: case PLAYLIST_LAST_PLAYED_STYLE_AGO:
last_played_human(runtime_log, tmp, sizeof(tmp)); if (!(runtime_last_played_human(runtime_log, tmp, sizeof(tmp))))
strlcat(tmp,
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_PLAYLIST_INLINE_CORE_DISPLAY_NEVER),
sizeof(tmp));
snprintf(str, len, "%s %s", snprintf(str, len, "%s %s",
msg_hash_to_str( msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED), MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED),