Use find_last_slash where possible

This commit is contained in:
LibretroAdmin 2025-01-17 13:26:17 +01:00
parent b47e09534c
commit dda78a4fc8
4 changed files with 6 additions and 20 deletions

View File

@ -6611,12 +6611,10 @@ static void retroarch_parse_input_libretro_path(
else else
{ {
size_t _len; size_t _len;
const char *slash = strrchr(path, '/');
const char *backslash = strrchr(path, '\\');
/* 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 */
if (((!slash || (backslash > slash)) ? (char*)backslash : (char*)slash)) if (find_last_slash(path))
goto end; goto end;
/* First check for built-in cores */ /* First check for built-in cores */

View File

@ -602,9 +602,7 @@ static bool content_file_list_set_info(
if (!string_is_empty(dir)) if (!string_is_empty(dir))
{ {
/* Remove any trailing slash */ /* Remove any trailing slash */
const char *slash = strrchr(dir, '/'); char *last_slash = find_last_slash(dir);
const char *backslash = strrchr(dir, '\\');
char *last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash;
if (last_slash && (last_slash[1] == '\0')) if (last_slash && (last_slash[1] == '\0'))
*last_slash = '\0'; *last_slash = '\0';

View File

@ -1287,9 +1287,7 @@ static void task_database_handler(retro_task_t *task)
if (!string_is_empty(db->fullpath)) if (!string_is_empty(db->fullpath))
{ {
const char *slash = strrchr(db->fullpath, '/'); char *last_slash = find_last_slash(db->fullpath);
const char *backslash = strrchr(db->fullpath, '\\');
char *last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash;
dirname = last_slash + 1; dirname = last_slash + 1;
} }
@ -1298,20 +1296,14 @@ static void task_database_handler(retro_task_t *task)
for (i = 0; i < dbstate->list->size; i++) for (i = 0; i < dbstate->list->size; i++)
{ {
char *last_slash; char *last_slash;
const char *slash;
const char *backslash;
const char *data = dbstate->list->elems[i].data; const char *data = dbstate->list->elems[i].data;
char *dbname = NULL;
bool strmatch = false; bool strmatch = false;
char *dbpath = strdup(data); char *dbpath = strdup(data);
path_remove_extension(dbpath); path_remove_extension(dbpath);
slash = strrchr(dbpath, '/'); last_slash = find_last_slash(dbpath);
backslash = strrchr(dbpath, '\\'); strmatch = strcasecmp(last_slash + 1, dirname) == 0;
last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash;
dbname = last_slash + 1;
strmatch = strcasecmp(dbname, dirname) == 0;
free(dbpath); free(dbpath);

View File

@ -501,9 +501,7 @@ void rarch_log_file_init(
{ {
/* Get log directory */ /* Get log directory */
const char *override_path = g_verbosity->override_path; const char *override_path = g_verbosity->override_path;
const char *slash = strrchr(override_path, '/'); const char *last_slash = find_last_slash(override_path);
const char *backslash = strrchr(override_path, '\\');
const char *last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash;
if (last_slash) if (last_slash)
{ {