Simplify path_basename

This commit is contained in:
libretroadmin 2023-07-17 15:13:13 +02:00
parent d26c4e52b3
commit a5f2903253

View File

@ -198,9 +198,9 @@ const char *path_get_archive_delim(const char *path)
string_to_lower(buf);
/* Check if this is a '.zip', '.apk' or '.7z' file */
if (string_is_equal(buf, ".zip") ||
string_is_equal(buf, ".apk") ||
string_is_equal(buf + 1, ".7z"))
if ( string_is_equal(buf, ".zip")
|| string_is_equal(buf, ".apk")
|| string_is_equal(buf + 1, ".7z"))
return delim;
}
else if (delim - path > 3)
@ -652,18 +652,12 @@ void path_parent_dir(char *path, size_t len)
**/
const char *path_basename(const char *path)
{
/* We cut at the first compression-related hash */
const char *delim = path_get_archive_delim(path);
if (delim)
return delim + 1;
{
/* We cut at the last slash */
const char *last = find_last_slash(path);
if (last)
return last + 1;
}
/* We cut either at the first compression-related hash,
* or we cut at the last slash */
const char *ptr = NULL;
if ( (ptr = path_get_archive_delim(path))
|| (ptr = find_last_slash(path)))
return ptr + 1;
return path;
}