From dda78a4fc80394da38c8c3c95a26ee4eccff5230 Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Fri, 17 Jan 2025 13:26:17 +0100 Subject: [PATCH] Use find_last_slash where possible --- retroarch.c | 4 +--- tasks/task_content.c | 4 +--- tasks/task_database.c | 14 +++----------- verbosity.c | 4 +--- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/retroarch.c b/retroarch.c index e4f4b94bebe..27aa4d2a0f2 100644 --- a/retroarch.c +++ b/retroarch.c @@ -6611,12 +6611,10 @@ static void retroarch_parse_input_libretro_path( else { size_t _len; - const char *slash = strrchr(path, '/'); - const char *backslash = strrchr(path, '\\'); /* If path has no extension and contains no path * delimiters, check if it is a core 'name', matching * an existing file in the cores directory */ - if (((!slash || (backslash > slash)) ? (char*)backslash : (char*)slash)) + if (find_last_slash(path)) goto end; /* First check for built-in cores */ diff --git a/tasks/task_content.c b/tasks/task_content.c index 10de01f9a11..eaa20b73151 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -602,9 +602,7 @@ static bool content_file_list_set_info( if (!string_is_empty(dir)) { /* Remove any trailing slash */ - const char *slash = strrchr(dir, '/'); - const char *backslash = strrchr(dir, '\\'); - char *last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash; + char *last_slash = find_last_slash(dir); if (last_slash && (last_slash[1] == '\0')) *last_slash = '\0'; diff --git a/tasks/task_database.c b/tasks/task_database.c index 310e9d3b72c..da6bfa1f27a 100644 --- a/tasks/task_database.c +++ b/tasks/task_database.c @@ -1287,9 +1287,7 @@ static void task_database_handler(retro_task_t *task) if (!string_is_empty(db->fullpath)) { - const char *slash = strrchr(db->fullpath, '/'); - const char *backslash = strrchr(db->fullpath, '\\'); - char *last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash; + char *last_slash = find_last_slash(db->fullpath); 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++) { char *last_slash; - const char *slash; - const char *backslash; const char *data = dbstate->list->elems[i].data; - char *dbname = NULL; bool strmatch = false; char *dbpath = strdup(data); path_remove_extension(dbpath); - slash = strrchr(dbpath, '/'); - backslash = strrchr(dbpath, '\\'); - last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash; - dbname = last_slash + 1; - strmatch = strcasecmp(dbname, dirname) == 0; + last_slash = find_last_slash(dbpath); + strmatch = strcasecmp(last_slash + 1, dirname) == 0; free(dbpath); diff --git a/verbosity.c b/verbosity.c index d785e88e152..5f46967846d 100644 --- a/verbosity.c +++ b/verbosity.c @@ -501,9 +501,7 @@ void rarch_log_file_init( { /* Get log directory */ const char *override_path = g_verbosity->override_path; - const char *slash = strrchr(override_path, '/'); - const char *backslash = strrchr(override_path, '\\'); - const char *last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash; + const char *last_slash = find_last_slash(override_path); if (last_slash) {