Skip to content

Commit

Permalink
Use find_last_slash where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Jan 17, 2025
1 parent b47e095 commit dda78a4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 20 deletions.
4 changes: 1 addition & 3 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 1 addition & 3 deletions tasks/task_content.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
14 changes: 3 additions & 11 deletions tasks/task_database.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);

Expand Down
4 changes: 1 addition & 3 deletions verbosity.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit dda78a4

Please sign in to comment.