Create string_ends_with_size

This commit is contained in:
twinaphex 2020-06-25 14:38:06 +02:00
parent e727e85b1d
commit de36ff20fb
17 changed files with 114 additions and 51 deletions

View File

@ -217,7 +217,8 @@ static int database_cursor_iterate(libretrodb_cursor_t *cur,
if (!string_is_empty(val_string))
db_info->franchise = strdup(val_string);
}
else if (string_ends_with(str, "_rating"))
else if (string_ends_with_size(str, "_rating",
strlen(str), STRLEN_CONST("_rating")))
{
if (string_is_equal(str, "bbfc_rating"))
{

View File

@ -56,21 +56,22 @@ static INLINE bool string_starts_with(const char *str, const char *prefix)
return (str && prefix) ? !strncmp(prefix, str, strlen(prefix)) : false;
}
static INLINE bool string_ends_with(const char *str, const char *suffix)
static INLINE bool string_ends_with_size(const char *str, const char *suffix,
size_t str_len, size_t suffix_len)
{
size_t str_len;
size_t suffix_len;
if (!str || !suffix)
return false;
str_len = strlen(str);
suffix_len = strlen(suffix);
return (str_len < suffix_len) ? false :
!memcmp(suffix, str + (str_len - suffix_len), suffix_len);
}
static INLINE bool string_ends_with(const char *str, const char *suffix)
{
if (!str || !suffix)
return false;
return string_ends_with_size(str, suffix, strlen(str), strlen(suffix));
}
#define STRLEN_CONST(x) ((sizeof((x))-1))
#define string_is_not_equal(a, b) !string_is_equal((a), (b))

View File

@ -1901,8 +1901,10 @@ int menu_cbs_init_bind_get_string_representation(menu_file_list_cbs_t *cbs,
if (!cbs)
return -1;
if ( string_starts_with_size(label, "input_player", STRLEN_CONST("input_player")) &&
string_ends_with(label, "joypad_index")
if ( string_starts_with_size(
label, "input_player", STRLEN_CONST("input_player")) &&
string_ends_with_size(label, "joypad_index", strlen(label),
STRLEN_CONST("joypad_index"))
)
{
BIND_ACTION_GET_VALUE(cbs, menu_action_setting_disp_set_label);

View File

@ -843,7 +843,8 @@ static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs,
}
if ( string_starts_with_size(label, "input_player", STRLEN_CONST("input_player")) &&
string_ends_with(label, "_joypad_index"))
string_ends_with_size(label, "_joypad_index", strlen(label),
STRLEN_CONST("_joypad_index")))
{
unsigned i;
for (i = 0; i < MAX_USERS; i++)
@ -916,7 +917,10 @@ static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_NO_ITEMS:
case MENU_ENUM_LABEL_NO_PLAYLIST_ENTRIES_AVAILABLE:
if (
string_ends_with(menu_label, "_tab")
string_ends_with_size(menu_label, "_tab",
strlen(menu_label),
STRLEN_CONST("_tab")
)
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
)
@ -931,7 +935,9 @@ static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_START_VIDEO_PROCESSOR:
case MENU_ENUM_LABEL_TAKE_SCREENSHOT:
if (
string_ends_with(menu_label, "_tab")
string_ends_with_size(menu_label, "_tab",
strlen(menu_label),
STRLEN_CONST("_tab"))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
)
{
@ -1062,7 +1068,8 @@ static int menu_cbs_init_bind_left_compare_type(menu_file_list_cbs_t *cbs,
case MENU_SETTING_GROUP:
case MENU_SETTINGS_CORE_INFO_NONE:
if (
string_ends_with(menu_label, "_tab")
string_ends_with_size(menu_label, "_tab",
strlen(menu_label), STRLEN_CONST("_tab"))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
)
{
@ -1098,7 +1105,8 @@ int menu_cbs_init_bind_left(menu_file_list_cbs_t *cbs,
if (type == MENU_SETTING_NO_ITEM)
{
if (
string_ends_with(menu_label, "_tab")
string_ends_with_size(menu_label, "_tab",
strlen(menu_label), STRLEN_CONST("_tab"))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
)

View File

@ -2138,7 +2138,9 @@ static int action_ok_playlist_entry_collection(const char *path,
* then copy the path without modification
* > If this is a standard core, ensure
* it has a corresponding core info entry */
if (string_ends_with(entry->core_path, "builtin"))
if (string_ends_with_size(entry->core_path, "builtin",
strlen(entry->core_path),
STRLEN_CONST("builtin")))
{
strlcpy(core_path, entry->core_path, sizeof(core_path));
core_is_builtin = true;
@ -5136,7 +5138,9 @@ static void netplay_refresh_rooms_cb(retro_task_t *task,
data->data = new_data;
data->data[data->len] = '\0';
if (!string_ends_with(data->data, "registry.lpl"))
if (!string_ends_with_size(data->data, "registry.lpl",
strlen(data->data),
STRLEN_CONST("registry.lpl")))
{
if (string_is_empty(data->data))
netplay_room_count = 0;
@ -6662,7 +6666,9 @@ static int menu_cbs_init_bind_ok_compare_label(menu_file_list_cbs_t *cbs,
return 0;
}
if (string_ends_with(str, "input_binds_list"))
if (string_ends_with_size(str, "input_binds_list",
strlen(str),
STRLEN_CONST("input_binds_list")))
{
unsigned i;

View File

@ -919,7 +919,8 @@ static int menu_cbs_init_bind_right_compare_type(menu_file_list_cbs_t *cbs,
case MENU_SETTING_GROUP:
case MENU_SETTINGS_CORE_INFO_NONE:
if (
string_ends_with(menu_label, "_tab")
string_ends_with_size(menu_label, "_tab",
strlen(menu_label), STRLEN_CONST("_tab"))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
)
{
@ -960,7 +961,8 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs,
}
if ( string_starts_with_size(label, "input_player", STRLEN_CONST("input_player")) &&
string_ends_with(label, "_joypad_index"))
string_ends_with_size(label, "_joypad_index", strlen(label),
STRLEN_CONST("_joypad_index")))
{
unsigned i;
for (i = 0; i < MAX_USERS; i++)
@ -1033,7 +1035,10 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_NO_ITEMS:
case MENU_ENUM_LABEL_NO_PLAYLIST_ENTRIES_AVAILABLE:
if (
string_ends_with(menu_label, "_tab")
string_ends_with_size(menu_label, "_tab",
strlen(menu_label),
STRLEN_CONST("_tab")
)
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
)
@ -1048,7 +1053,9 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_START_VIDEO_PROCESSOR:
case MENU_ENUM_LABEL_TAKE_SCREENSHOT:
if (
string_ends_with(menu_label, "_tab")
string_ends_with_size(menu_label, "_tab",
strlen(menu_label),
STRLEN_CONST("_tab"))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
)
{
@ -1104,7 +1111,9 @@ int menu_cbs_init_bind_right(menu_file_list_cbs_t *cbs,
if (type == MENU_SETTING_NO_ITEM)
{
if (
string_ends_with(menu_label, "_tab")
string_ends_with_size(menu_label, "_tab",
strlen(menu_label),
STRLEN_CONST("_tab"))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU))
|| string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU))
)

View File

@ -9611,7 +9611,8 @@ static void materialui_list_insert(
node->icon_texture_index = MUI_TEXTURE_PLAYLIST;
node->has_icon = true;
}
else if (string_ends_with(label, "_input_binds_list"))
else if (string_ends_with_size(label, "_input_binds_list",
strlen(label), STRLEN_CONST("_input_binds_list")))
{
unsigned i;

View File

@ -850,7 +850,8 @@ void ozone_context_reset_horizontal_list(ozone_handle_t *ozone)
if (!path)
continue;
if (!string_ends_with(path, ".lpl"))
if (!string_ends_with_size(path, ".lpl",
strlen(path), STRLEN_CONST(".lpl")))
continue;
{
@ -968,7 +969,8 @@ void ozone_context_destroy_horizontal_list(ozone_handle_t *ozone)
file_list_get_at_offset(ozone->horizontal_list, i,
&path, NULL, NULL, NULL);
if (!path || !string_ends_with(path, ".lpl"))
if (!path || !string_ends_with_size(path, ".lpl",
strlen(path), STRLEN_CONST(".lpl")))
continue;
video_driver_texture_unload(&node->icon);

View File

@ -1837,7 +1837,8 @@ static void stripes_context_destroy_horizontal_list(stripes_handle_t *stripes)
file_list_get_at_offset(stripes->horizontal_list, i,
&path, NULL, NULL, NULL);
if (!path || !string_ends_with(path, ".lpl"))
if (!path || !string_ends_with_size(path, ".lpl",
strlen(path), STRLEN_CONST(".lpl")))
continue;
video_driver_texture_unload(&node->icon);
@ -1935,7 +1936,8 @@ static void stripes_context_reset_horizontal_list(
file_list_get_at_offset(stripes->horizontal_list, i,
&path, NULL, NULL, NULL);
if (!path || !string_ends_with(path, ".lpl"))
if (!path || !string_ends_with_size(path, ".lpl",
strlen(path), STRLEN_CONST(".lpl")))
continue;
{

View File

@ -2032,7 +2032,8 @@ static void xmb_context_destroy_horizontal_list(xmb_handle_t *xmb)
file_list_get_at_offset(xmb->horizontal_list, i,
&path, NULL, NULL, NULL);
if (!path || !string_ends_with(path, ".lpl"))
if (!path || !string_ends_with_size(path, ".lpl",
strlen(path), STRLEN_CONST(".lpl")))
continue;
video_driver_texture_unload(&node->icon);
@ -2131,7 +2132,8 @@ static void xmb_context_reset_horizontal_list(
if (!path)
continue;
if (!string_ends_with(path, ".lpl"))
if (!string_ends_with_size(path, ".lpl",
strlen(path), STRLEN_CONST(".lpl")))
continue;
{

View File

@ -1134,7 +1134,8 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info,
if (
string_is_equal(path_playlist, "history") ||
string_is_equal(path_playlist, "favorites") ||
string_ends_with(path_playlist, "_history"))
string_ends_with_size(path_playlist, "_history",
strlen(path_playlist), STRLEN_CONST("_history")))
{
char system_name[15];
system_name[0] = '\0';
@ -1989,7 +1990,8 @@ static void menu_displaylist_set_new_playlist(
/* Get proper playlist capacity */
if (!string_is_empty(playlist_file_name))
{
if (string_ends_with(path, "_history.lpl"))
if (string_ends_with_size(path, "_history.lpl",
strlen(path), STRLEN_CONST("_history.lpl")))
playlist_size = content_history_size;
else if (string_is_equal(playlist_file_name, file_path_str(FILE_PATH_CONTENT_FAVORITES)))
if (content_favorites_size >= 0)
@ -2464,7 +2466,8 @@ static int menu_displaylist_parse_horizontal_content_actions(
remove_entry_enabled =
string_is_equal(system, "history") ||
string_is_equal(system, "favorites") ||
string_ends_with(system, "_history");
string_ends_with_size(system, "_history",
strlen(system), STRLEN_CONST("_history") );
/* An annoyance: if the user navigates to the information menu,
* then to the database entry, the thumbnail system will be changed.
@ -2565,7 +2568,8 @@ static int menu_displaylist_parse_horizontal_content_actions(
menu_driver_get_thumbnail_system(system, sizeof(system));
if (!string_is_empty(system))
download_enabled = !string_ends_with(system, "_history");
download_enabled = !string_ends_with_size(
system, "_history", strlen(system), STRLEN_CONST("_history"));
}
if (settings->bools.network_on_demand_thumbnails)
@ -2815,7 +2819,8 @@ static unsigned menu_displaylist_parse_playlists(
/* Ignore history/favourites */
if (
string_ends_with(path, "_history.lpl")
string_ends_with_size(path, "_history.lpl",
strlen(path), STRLEN_CONST("_history.lpl"))
|| string_is_equal(playlist_file,
file_path_str(FILE_PATH_CONTENT_FAVORITES)))
continue;
@ -3084,7 +3089,8 @@ static unsigned menu_displaylist_parse_playlist_manager_list(
* > content_history + favorites are handled separately
* > music/video/image_history are ignored */
if (
string_ends_with(path, "_history.lpl")
string_ends_with_size(path, "_history.lpl",
strlen(path), STRLEN_CONST("_history.lpl"))
|| string_is_equal(playlist_file,
file_path_str(FILE_PATH_CONTENT_FAVORITES)))
continue;
@ -3162,7 +3168,9 @@ static bool menu_displaylist_parse_playlist_manager_settings(
return false;
/* Check whether this is a content history playlist */
is_content_history = string_ends_with(playlist_path, "_history.lpl");
is_content_history = string_ends_with_size(
playlist_path, "_history.lpl", strlen(playlist_path),
STRLEN_CONST("_history.lpl"));
/* Default core association
* > This is only shown for collection playlists

View File

@ -152,8 +152,11 @@ void cb_net_generic_subdir(retro_task_t *task,
subdir_path[data->len] = '\0';
finish:
if (!err && !string_ends_with(subdir_path,
file_path_str(FILE_PATH_INDEX_DIRS_URL)))
if (!err && !string_ends_with_size(subdir_path,
file_path_str(FILE_PATH_INDEX_DIRS_URL),
strlen(subdir_path),
strlen(file_path_str(FILE_PATH_INDEX_DIRS_URL))
))
{
char parent_dir[PATH_MAX_LENGTH];
@ -221,7 +224,11 @@ finish:
}
if (!err &&
!string_ends_with(state->path, file_path_str(FILE_PATH_INDEX_DIRS_URL)))
!string_ends_with_size(state->path,
file_path_str(FILE_PATH_INDEX_DIRS_URL),
strlen(state->path),
strlen(file_path_str(FILE_PATH_INDEX_DIRS_URL))
))
{
char *parent_dir = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
char *parent_dir_encoded = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));

View File

@ -2755,7 +2755,8 @@ void playlist_get_db_name(playlist_t *playlist, size_t idx,
* (i.e. ignore history/favourites) */
if (
!string_is_empty(conf_path_basename)
&& !string_ends_with(playlist->conf_path, "_history.lpl")
&& !string_ends_with_size(playlist->conf_path, "_history.lpl",
strlen(playlist->conf_path), STRLEN_CONST("_history.lpl"))
&& !string_is_equal(conf_path_basename,
file_path_str(FILE_PATH_CONTENT_FAVORITES))
)

View File

@ -19332,7 +19332,8 @@ static bool libretro_get_system_info(
dylib_t lib;
#endif
if (string_ends_with(path, "builtin"))
if (string_ends_with_size(path,
"builtin", strlen(path), STRLEN_CONST("builtin")))
return false;
dummy_info.library_name = NULL;
@ -34856,7 +34857,8 @@ static void retroarch_parse_input_and_config(
{
int path_stats;
if (string_ends_with(optarg, "builtin"))
if (string_ends_with_size(optarg, "builtin",
strlen(optarg), STRLEN_CONST("builtin")))
{
RARCH_LOG("--libretro argument \"%s\" is a built-in core. Ignoring.\n",
optarg);

View File

@ -353,7 +353,8 @@ void* task_push_http_transfer_file(const char* url, bool mute,
strlcpy(tmp, msg_hash_to_str(MSG_DOWNLOADING), sizeof(tmp));
strlcat(tmp, " ", sizeof(tmp));
if (string_ends_with(s, ".index"))
if (string_ends_with_size(s, ".index",
strlen(s), STRLEN_CONST(".index")))
strlcat(tmp, msg_hash_to_str(MSG_INDEX_FILE), sizeof(tmp));
else
strlcat(tmp, s, sizeof(tmp));

View File

@ -266,7 +266,9 @@ static void task_netplay_crc_scan_handler(retro_task_t *task)
const char *lpl_path = state->lpl_list->elems[i].data;
/* skip files without .lpl file extension */
if (!string_ends_with(lpl_path, ".lpl"))
if (!string_ends_with_size(lpl_path, ".lpl",
strlen(lpl_path),
STRLEN_CONST(".lpl")))
continue;
RARCH_LOG("[Lobby]: Searching playlist: %s\n", lpl_path);
@ -340,7 +342,9 @@ static void task_netplay_crc_scan_handler(retro_task_t *task)
const char *lpl_path = state->lpl_list->elems[j].data;
/* skip files without .lpl file extension */
if (!string_ends_with(lpl_path, ".lpl"))
if (!string_ends_with_size(lpl_path, ".lpl",
strlen(lpl_path),
STRLEN_CONST(".lpl")))
continue;
RARCH_LOG("[Lobby]: Searching content %d/%d (%s) in playlist: %s\n", i + 1, game_list->size, game_list->elems[i].data, lpl_path);

View File

@ -492,7 +492,10 @@ bool task_push_pl_thumbnail_download(
/* Only parse supported playlist types */
if (
string_ends_with(playlist_path, "_history.lpl")
string_ends_with_size(playlist_path, "_history.lpl",
strlen(playlist_path),
STRLEN_CONST("_history.lpl")
)
|| string_is_equal(playlist_file,
file_path_str(FILE_PATH_CONTENT_FAVORITES))
|| string_is_equal(system, "history")
@ -796,7 +799,10 @@ bool task_push_pl_entry_thumbnail_download(
goto error;
/* Only parse supported playlist types */
if (string_ends_with(system, "_history"))
if (string_ends_with_size(system, "_history",
strlen(system),
STRLEN_CONST("_history")
))
goto error;
/* Copy playlist path